有没有人知道在JavaScript中的window.document.write('')
的jQuery等价物? 谢谢jQuery等价于window.document.write
回答
这将增加身体的结束标记前右侧的字符串 “hello”。不完全是write
的行为,但您可以对任何元素执行此操作,以使内容出现在您想要的位置。
$(document.body).append('hello');
此外,还包括prepend(content)
和replaceWith(content)
满足您的所有需求插入!
+1 @ctcherry ...这正是我正在寻找的。 – 2011-03-30 17:59:43
当然,如果你只是想替换整个身体,为什么不:: document.body.innerHTML ='...'这是少打字,并不需要几千行库代码,使其工作。 – RobG 2011-03-30 23:06:21
首先,jQuery 是 JavaScript,它只是一个函数库,使编码更容易。
二,你应该避免使用document.write
。您应该使用jQuery将文本追加到所需的DOM元素。
例子:
$('#myDiv').append('some new text')
+1 @Rocket ...感谢您的建议......我知道jQuery是一个JavaScript库,但我寻找jQuery等价物的原因是我想编写跨浏览器兼容的代码,只要我能够。 – 2011-03-30 18:02:38
@Kyaw:没有“document.write”的“jQuery等价物”,这没有任何意义。你不需要* jQuery来编写跨浏览器的代码,但它确实有帮助。 – 2011-03-30 18:06:13
@Kyaw:对于某些人来说,vanilla JavaScript工作得很好,对于其他人来说,jQuery是最好的选择。这完全取决于你想要做什么。 – 2011-03-30 18:12:46
尝试使用这个例子:
table = $('#flightTypeEditTemplate').clone();
table.attr('id','');
document.write(table.html());`
- 1. jQuery等价于querySelector
- 2. jquery等价于form.field_name?
- 3. jQuery等价于PHP的file_exists()?
- 4. 等价于getbounds
- 5. jQuery的等价于“使”输入
- 6. 在jQuery中,$(func)等价于$(document).ready(func)?
- 7. 等价于jquery中的$ .curCSS方法1.10
- 8. jQuery等价于XMLHttpRequest的上传?
- 9. jQuery等价于PrototypeJs的Hash()类吗?
- 10. Dojo等价于jQuery的.data()方法
- 11. 在jQuery中等价于$('input [name $ =“value”]')?
- 12. windows等价于inet_aton
- 13. DataGridView等价于DataGrid.NavigateTo()
- 14. jconsole等价于.Net?
- 15. XmlSerializer等价于IExtensibleDataObject
- 16. java等价于mkstemp
- 17. “TYPEOF”等价于Mysql?
- 18. JVMTI等价于.NET
- 19. viewWillDisappear等价于CCScenes
- 20. Scala等价于pyTables?
- 21. C++等价于Tidy
- 22. ASMX等价于Page_Init?
- 23. JMS等价于.Net
- 24. Application.ProductName等价于WPF?
- 25. getModel等价于ModelForms?
- 26. ART等价于dvmDumpAllThreads
- 27. C++等价于SerializeWithLengthPrefix
- 28. SizeToContent等价于WinForm?
- 29. WPF等价于TextRenderer
- 30. GLSL等价于sampler_state?
他没有说事实并非如此。 – dtbarne 2012-12-17 23:51:25