【发布时间】:2011-07-26 06:55:52
【问题描述】:
有谁知道 jQuery 中 window.document.write('') 在 javascript 中的等价物吗?
谢谢
【问题讨论】:
标签: javascript jquery jquery-selectors javascript-framework
有谁知道 jQuery 中 window.document.write('') 在 javascript 中的等价物吗?
谢谢
【问题讨论】:
标签: javascript jquery jquery-selectors javascript-framework
尝试使用这个例子:
table = $('#flightTypeEditTemplate').clone();
table.attr('id','');
document.write(table.html());`
【讨论】:
这将在正文结束标记之前添加字符串“hello”。不完全是 write 的行为,但您可以对任何元素执行此操作,以使内容出现在您想要的位置。
$(document.body).append('hello');
prepend(content) 和 replaceWith(content) 也可以满足您的所有插入需求!
【讨论】:
首先,jQuery是 JavaScript,它只是一个函数库,让编码更容易。
其次,你应该避免使用document.write。您应该使用 jQuery 将文本附加到所需的 DOM 元素。
例子:
$('#myDiv').append('some new text')
【讨论】:
document.write 的“jQuery 等价物”,这没有任何意义。你不需要 jQuery 来编写跨浏览器代码,但它确实有帮助。