window.onload=function(){
var container = document.getElementById('container'),
template = '<li>\
<input type="checkbox">\
</li>\
<li>\
<input type="checkbox">\
</li>\
<li>\
<input type="checkbox">\
</li>';
container.onchange = function(e) {
var event = e || window.event,
target = event.srcElement || event.target;
if(target.checked && target.parentNode.getElementsByTagName('ul').length === 0) {
var ul = document.createElement('ul');
ul.innerHTML = template;
target.parentNode.appendChild(ul);
} else {
var ul = target.parentNode.getElementsByTagName('ul')[0];
target.parentNode.removeChild(ul);
}
};
}
<ul id="container">
<li>
<input type="checkbox">
</li>
<li>
<input type="checkbox">
</li>
<li>
如何唯一id分配給在上述代碼中的每個複選框.................如何將一個唯一的ID分配給每個複選框
<input type="checkbox">
</li>
</ul>
如何改變這種代碼....... ... – thuk 2011-05-27 13:31:33
改變它做什麼? – 2011-05-27 13:32:06