-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsudoku.html
126 lines (118 loc) · 3.2 KB
/
sudoku.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<!doctype html>
<html class="no-js">
<head>
<meta charset="utf-8">
<title>数独</title>
<meta name="format-detection" content="telephone=no">
<meta name="viewport" content="width=device-width,user-scalable=no,initial-scale=1,maximum-scale=1,minimum-scale=1">
<meta name="apple-mobile-web-app-capable" content="yes">
<style type="text/css">
*{
margin : 0;
padding : 0;
}
div{
box-sizing : border-box;
}
#grid{
width: 452px;
height: 450px;
margin: 100px auto;
border: 1px solid #888;
}
.sudoku{
width: 150px;
height: 150px;
border: 1px solid #888;
float: left;
overflow: hidden;
}
.square{
width: 50px;
height: 50px;
line-height: 50px;
text-align: center;
border-left: 1px solid #ccc;
border-top: 1px solid #ccc;
margin: -1px 0px 0px -1px;
float: left;
}
.square-input{
display: block;
width: 100%;
height: 100%;
border: 0px;
text-align: center;
font-size: 24px;
outline: none;
}
.btn-grid{
display: block;
width: 100px;
height: 30px;
line-height: 30px;
text-align: center;
border: 1px solid #333;
border-radius: 30px;
margin: 50px auto;
}
</style>
</head>
<body>
<div id="grid"></div>
<a class="btn-grid" href="javascript:;">grid</a>
<script type="text/template" id="tpl">
<% for(var i=0;i<9;i++){ %>
<div class="sudoku">
<% for(var j=0;j<9;j++){ %>
<div class="square"><input class="square-input" <%= (obj && grid[i][j]) ? "disabled" : "" %> value=<%= (obj && grid[i][j]) ? grid[i][j] : ' "" ' %> data-value= <%= i+','+j %> /> </div>
<% } %>
</div>
<% } %>
</script>
<script src="jquery-2.1.4.min.js"></script>
<script src="underscore.js"></script>
<script type="text/javascript">
var tpl = _.template($('#tpl').html());
var gridData = {"grid":[
[0,1,2,3,4,5,6,7,8],
[0,1,2,3,4,5,6,7,8],
[0,1,2,3,4,5,6,7,8],
[0,1,2,3,4,5,6,7,8],
[0,1,2,3,4,5,6,7,8],
[0,1,2,3,4,5,6,7,8],
[0,1,2,3,4,5,6,7,8],
[0,1,2,3,4,5,6,7,8],
[0,1,2,3,4,5,6,7,8]
]};
var gridData = {
"grid" : [[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0],[0,0,0,0,0,0,0,0,0]]
}
$('#grid').html(tpl(gridData))
$('.btn-grid').bind('click',function(){
getGridData();
})
function getGridData(){
var gridData = [];
var sudoku = $('.sudoku');
var square = $('.square');
sudoku.each(function(){
var that = $(this);
var square = that.find('.square-input');
var sudokuData = [];
square.each(function(){
var that = $(this);
var thatVal = that.val();
if(thatVal){
sudokuData.push(parseInt(thatVal));
}else{
sudokuData.push(0);
}
})
gridData.push(sudokuData);
})
console.log(JSON.stringify(gridData));
}
</script>
</body>
</html>