我在CreateElemant中使用JavaScript --这是我的代码:
function generateInputs()
{
var i = document.createElement("input");
for(var j=0;j<4;j++)
{
var c = document.createElement("input");
var r = document.createElement("input");
r.setAttribute('type',"radio");
document.getElementById('questions').appendChild(r);
c.setAttribute('type',"input");
document.getElementById('questions').appendChild(c);
}
i.setAttribute('type',"text");
document.getElementById('questions').appendChild(i);
}我想用jQuery写它,但是我没有找到与jQuery等价的
发布于 2014-04-03 16:39:15
只需试着:
function generateInputs()
{
var i = $('<input type="text"/>');
for(var j=0;j<4;j++)
{
var c = $('<input type="text"/>');
var r = $('<input type="radio"/>');
$('#questions').append(c).append(r);
}
$('#questions').append(i);
}发布于 2014-04-03 16:38:25
// $("#id"), $("element") or $(".class") for selecting parent
$("#foo").append("<div>hello world</div>")
var txt1="<p>Text.</p>"; // Create element with HTML
var txt2=$("<p></p>").text("Text."); // Create with jQuery
var txt3=document.createElement("p"); // Create with DOM
txt3.innerHTML="Text.";
$("p").append(txt1,txt2,txt3); // Append the new elements 发布于 2014-04-03 16:39:19
$('<input />').attr('type','radio').appendTo(document.body)有些是这样的
https://stackoverflow.com/questions/22843777
复制相似问题