我有一个页面加载,然后我做了一些JQuery。在做行时:
var div = $("<div class='modal'>").append(r);
我试图找出错误原因,并说有一个层次结构错误。也许r中存在不正确的DOM?为了节省输出,我会显示服务器端。下面的r不会出错,但是在将上面的div附加到实际出现问题的地方时就是错误。
var r = $(result);
结果:
"<div>
<input type='text' id ='queryInput' />
<button id = 'queryButton' runat='server' value = 'Re-Filter'>Re-Filter</button>
</div>
<div id='set'>
<select>
<!-- The options are populated by a loop in ASP.net -->
<option value = '" + Convert.ToString(record.fe_id) + "'>" + Convert.ToString(record.fe_name) + "</option>
</select>
</div>
<div>
<button id = 'buttonReturnValue' value = 'Return Selected Element'>Return Selected Element</button>
</div>"
在认为上述情况不正确的情况下,我做错了什么?
答案 0 :(得分:2)
var text = "<div><input type='text' id ='queryInput' /><button id = 'queryButton' runat='server' value = 'Re-Filter'>Re-Filter</button></div><div id='set'><select><option value = '" + Convert.ToString(record.fe_id) + "'>" + Convert.ToString(record.fe_name) + "</option></select></div><div><button id = 'buttonReturnValue' value = 'Return Selected Element'>Return Selected Element</button></div>";
这是一种解决方法,但有效......
var d = document.createElement("div");
d.innerHTML = text;
document.getElementById('modal').appendChild(d);