【发布时间】:2015-05-11 09:34:21
【问题描述】:
我的 div 生成有问题,因为我生成了一个表单,我想将它们包装在具有相同 id 的 div 中。但是当我检查元素时,它会在表单之前自动关闭。所以它不会像假设的那样环绕它,它只是在表单上方<div></div>。
var startDiv = "<div id='appm'>";
var endDiv = "</div>";
for(var i = 0; i < values.length; i = i + 8){
$('#youEvents').append(
$('<form />', { id: values[i], method: 'POST' }).append(
startDiv, // Starting div id=appm
$('<textarea />', { id: "teast", name: 'routename', placeholder: 'Name', value: values[i], type: 'text' }),
$('<br />'),
$('<input />', { id: 'rname', name: 'routename', placeholder: 'Name', value: values[i + 1], type: 'text' }),
$('<br />'),
$('<input />', { id: 'rname', name: 'routename', placeholder: 'Name', value: values[i + 2], type: 'text' }),
$('<br />'),
$('<input />', { id: 'rname', name: "ee", placeholder: 'Name', value: values[i + 3], type: 'text' }),
$('<br />'),
$('<input />', { id: 'rname', name: 'routename', placeholder1: 'Name', value: values[i + 4], type: 'text' }),
$('<br />'),
$('<input />', { id: 'rname', name: 'routename', placeholder: 'Name', value: values[i + 5], type: 'text' }),
$('<br />'),
$('<input />', { id: 'address', id: 'rdescription', name: 'heya', value: values[i + 6], type: 'text' }),
$('<br />'),
$('<input />', { id: 'adress', name: 'routetags', placeholder: 'tags', value: values[i + 7], type: 'text' }),
$('<br />'),
$('<input />', { id: values[i], type: 'button', value: 'Submit', click: function(){
// attaching the function to the button
testAjax(this.id); // Calling the function below.
}}),
endDiv // Ending the div
)
);
}
【问题讨论】:
标签: javascript jquery html dom append