Javascript 如何对同一createElement变量多次使用appendChild
我试图使它,以便当我在最新的输入一个新的东西被创建,但它只与一个工作Javascript 如何对同一createElement变量多次使用appendChild,javascript,html,css,Javascript,Html,Css,我试图使它,以便当我在最新的输入一个新的东西被创建,但它只与一个工作 $(document).ready(function() { $( function() { $("#list").draggable(); }); var count = 1; var timer = 0; var input = document.createElement("input"); input.type = "text"; init();
$(document).ready(function() {
$( function() {
$("#list").draggable();
});
var count = 1;
var timer = 0;
var input = document.createElement("input");
input.type = "text";
init();
function init() {
loop();
}
function loop() {
requestAnimFrame(function() {
loop();
});
update();
render();
}
function update() {
console.log(count);
if(document.getElementById(count).value == "") {
} else {
count += 1;
}
var = div.cloneNode(true);
document.getElementById("list").appendChild(input);
}
function render() {
input.id = count;
input.name = count;
}
});
window.requestAnimFrame = (function() {
return window.requestAnimationFrame ||
window.oRequestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
function( callback ) {
window.setTimeout(callback, 1000/60);
}
})();
这就是javascript。经过一些调整后,我得到了答案
count += 1;
var input = document.createElement("input");
input.id = count;
input.name = count;
input.type = "text";
document.getElementById("list").appendChild(input);
我需要重述它以重新创建它,然后设置它。
看看这个,它可能有助于克隆元素
$(document).ready(function() {
var count = 1;
var timer = 0;
var input = $("<input></input>", {
'type':'text',
'class':'form-control',
'value':'1',
'id':'count'
});
for(var i=1;i!=11;i++) {
input.val(count++);
$("#list").append(input.clone());
}
});
$(文档).ready(函数(){
var计数=1;
var定时器=0;
变量输入=$(“”{
“类型”:“文本”,
“类”:“窗体控件”,
“值”:“1”,
“id”:“count”
});
对于(变量i=1;i!=11;i++){
val(count++);
$(“#list”).append(input.clone());
}
});
不需要包含JQuery。很高兴您找到了它。看看克隆,你可能会发现它比娱乐更方便:)
document.getElementById("list").appendChild(input.cloneNode(true));