使用DOM方式進行動態頁面創建
使用普通的DOM方式為input type='checkbox'和input type='radio'賦初值。即下面的語句:?var input = document.createElement('INPUT');
?input.type = 'checkbox';
?input.checked = true;
?document.body.appendChild(input);
?input = document.createElement('INPUT');
?input.type = 'radio';
?input.checked = true;
?document.body.appendChild(input);
??? 不能得到我期望的效果:?,而只能得到:?。
??? 而要得到我期望的效果,需要混合DHTML和DOM兩種方式就是說我必須在sTag里就構建好的屬性,使用如下代碼:
?var input = document.createElement('<INPUT checked>');
?input.type = 'checkbox';
?document.body.appendChild(input);
?input = document.createElement('<INPUT checked>');
?input.type = 'radio';
?document.body.appendChild(input);
?類似的,如果需要在創建的元素中支持js腳本調用,只需要采用類似以下的方法:
var input_4 = document.createElement("<input name='button' onclick='hide(\"para"+show_int+"\");'>");