forked from chubby/happy_lights
create table, add palitra
This commit is contained in:
commit
2c707dafc1
18
index.html
Normal file
18
index.html
Normal file
@ -0,0 +1,18 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<style>
|
||||
.table td{
|
||||
padding: 10px;
|
||||
border: 1px solid black
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<table class='table' id='qq' ></table>
|
||||
<input type='color' id='palitra' >
|
||||
|
||||
<script src="main.js"></script>
|
||||
|
||||
</body>
|
||||
</html>
|
44
main.js
Normal file
44
main.js
Normal file
@ -0,0 +1,44 @@
|
||||
|
||||
let elem = document.getElementById('qq');
|
||||
|
||||
let a_click = false
|
||||
|
||||
|
||||
function createTable (parent, cols, rows){
|
||||
let table = document.createElement('table')
|
||||
document.onmousedown = function(){
|
||||
a_click = true
|
||||
}
|
||||
|
||||
document.onmouseup = function(){
|
||||
a_click = false
|
||||
}
|
||||
let palitra = document.getElementById('palitra');
|
||||
|
||||
for ( i=0; i<rows; i++){
|
||||
let tr=document.createElement('tr')
|
||||
|
||||
|
||||
for (j=0; j<cols; j++){
|
||||
|
||||
let td = document.createElement('td')
|
||||
td.onmouseover = function(){
|
||||
if (a_click){
|
||||
|
||||
td.style.backgroundColor = palitra.value
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
td.onclick = function(){
|
||||
td.style.backgroundColor = palitra.value
|
||||
}
|
||||
|
||||
tr.append(td)
|
||||
}
|
||||
table.append(tr)
|
||||
}
|
||||
parent.append(table)
|
||||
}
|
||||
|
||||
createTable (elem, 20, 20)
|
Loading…
x
Reference in New Issue
Block a user