日期:2014-05-16 浏览次数:20439 次
document.getElementById('a').innerHTML += '<input type="radio" name="id1" value="1">';
var control = document.createElement("input");
control.setAttribute("type", "radio");
var text = document.createTextNode('你的文字');
document.body.appendChild(control);
document.body.appendChild(text)
function test(){
var e = createElement('input','sex', 'radio', '1');
board.appendChild(e);
var label = document.createElement("label");
label.innerHTML = "Male";
board.appendChild(label);
var d = createElement('input','sex', 'radio', '2');
board.appendChild(d);
var text = document.createTextNode('Female');
board.appendChild(text);
}
/*创建控件*/
function createElement(tagName,name,type,value)
{
var element = null;
try
{
element = document.createElement('<'+tagName+' name="'+name+'" />');
element.type = type;
element.value = value;
}
catch (e)
{
}
if (!element)
{
element = document.createElement(tagName);
element.setAttribute("type",type);
element.setAttribute("name",name);
element.setAttribute("value",value);
}
return element;
}