日期:2014-05-16  浏览次数:20371 次

如何用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);