0
同じセル内にあれば、ボタンをペアで動作させる方法と、すべてのボタンを個別に認識するスクリプトはありますか?
function functionAdd() {
***> here I add cells and rows to the table***
----------------------------------------
var table = document.getElementById("id");
var row = table.insertRow(1);
var cell = row.insertCell(0);
var cell1 = row.insertCell(1);
var cell2 = row.insertCell(2);
var cell3 = row.insertCell(3);
cell.innerHTML = "New function";
cell1.innerHTML = "<div class='row'>"+
" <button type='button' id='on'>ON</button>"+
" <button type='button' id='off'>OFF</button>"+
"</div>";
cell1.style.width = '100px';
cell2.innerHTML = " <img src='greenPoint.png' style = 'width: 10px; height:10px;'>"
cell3.innerHTML = " <img src='deleteIcon.png' style = 'width: 20px; height:20px;'>"
***> there is the condition for buttons***
document.getElementById('on').disabled = false;
document.getElementById('off').disabled = false;
//on click changes on/off to green
document.getElementById('on').onclick = function(){
this.disabled = true;
document.getElementById('off').disabled = false;
if (this.disabled == false) {
document.getElementById('off').disabled = true;
}else if (this.disabled == true) {
document.getElementById('off').disabled = false;
}
cell2.innerHTML = " <img src='greenPoint.png' style = 'width: 10px; height:10px;'>"
}
//on click changes on/off to red
document.getElementById('off').onclick = function(){
this.disabled = true;
document.getElementById('on').disabled = false;
cell2.innerHTML = " <img src='redPoint.png' style = 'width: 10px; height:10px;'>"
}
}
table
{
margin: 0 auto;
width:350px;
height:100px;
}
.row
{
text-align: center;
}
.log{
margin: 200px 455px;
background-color: #2980b9;
border-radius: 4px;
}
.input{
padding-top: 20px;
padding-bottom: 20px;
margin-left: 35px;
}
input{
margin-top: 10px;
margin-left: 20px;
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body>
<div id="vizibilitate">
<input type="button" value="Add" onclick="functionAdd()">
<table id="id" style="border:1px solid black; border-radius: 3px;">
<tr>
<th>denumirea</th>
<th>statut</th>
<th>on/off</th>
<th >delete</th>
</tr>
<tr>
</tr>
</table>
</div>
</body>
</html>
のように私はオンとオフのための最初の行のみに変更を加えることができますが、他の行は、私は解決策を持って無効ボタン