Javascript jQuery 等效于 window.document.write
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5489989/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery equivalent for window.document.write
提问by Kyaw Thurein
Does anyone know the jQuery equivalent for window.document.write('')
in javascript?
Thanks
有谁知道window.document.write('')
javascript 中的 jQuery 等价物?谢谢
回答by ctcherry
This will add the string "hello" right before the body closing tag. Not exactly the behavior of write
, but you can do this to any element to get the content to appear where you want it.
这将在正文结束标记之前添加字符串“hello”。不完全是 的行为write
,但您可以对任何元素执行此操作,以使内容出现在您想要的位置。
$(document.body).append('hello');
Also available are prepend(content)
and replaceWith(content)
for all your insertion needs!
此外,还包括prepend(content)
和replaceWith(content)
所有的插入需求!
回答by Rocket Hazmat
First, jQuery isJavaScript, it is just a library of functions to make coding easier.
首先,jQuery是JavaScript,它只是一个使编码更容易的函数库。
Second, you should avoid the use of document.write
. You should use jQuery to append the text to the DOM element you want.
其次,您应该避免使用document.write
. 您应该使用 jQuery 将文本附加到您想要的 DOM 元素。
Example:
例子:
$('#myDiv').append('some new text')
回答by user2206859
Try to use this example:
尝试使用这个例子:
table = $('#flightTypeEditTemplate').clone();
table.attr('id','');
document.write(table.html());`