您现在的位置是:首页 > 电脑技术查询 > web开发

怎么用appendChild()方法添加表单

编辑:chaxungu时间:2022-10-02 23:20:53分类:web开发

如何用appendChild()方法添加表单
如何用appendChild()方法添加表单,如,我想在 <p id= "p1 "> &nbsp; </p> 中加入
一个含有事件的按扭 <input type= "button " value= "myButton " id= "btn1 " name= "btn1 " onclick= "checkValue() "> ????

------解决方案--------------------
<p id= "p1 "> </p>
<script>
function clickme() {
alert(1);
}

function createInput(parentObj){
var input = document.createElement( 'input ');
input.type = 'button ';
input.value = 'myButton ';
input.id = 'btn1 ';
input.name = 'btn1 ';
input.onclick = clickme;

parentObj.appendChild(input);
}
createInput(document.getElementById( 'p1 '));
</script>
------解决方案--------------------
var oInput = document.createElement( "input ");
with(oInput)
{
type = "button ";
value = "myButton ";
id = name = "btn1 ";
onclick = funcition(){checkValue()};
}

XXXform.appendChild(oInput);