简体   繁体   English

jQuery .html在包含的文件上

[英]jquery .html on an included file

I have viewed this answer jquery append external html file into my page 我已经查看了这个答案jQuery将外部html文件附加到我的页面中

And was wondering if it applied to my situation. 并且想知道它是否适用于我的情况。

I have a page that includes another, can I use the jquery .html() to inject html on the included page? 我的页面包含另一个页面,我可以使用jquery .html()在包含的页面上注入html吗?

<html><body>some text <includedpage.html></body></html>

If includedpage.html contains a div <div class="demo-container"> Can I inject as such:? 如果includedpage.html包含div <div class="demo-container">我可以这样注入吗? $('div.demo-container') .html('<p>All new content. <em>You bet!</em></p>');

Will this work? 这样行吗?

Yes, it should work, assuming that when you inspect the DOM after including the file, 是的,它应该工作,假设当您在包含文件后检查DOM时,

<html><body>some text <includedpage.html></body></html>

has become 已经成为

<html><body>some text<div class="demo-container"></div></body></html>

jQuery operates on the current DOM structure of the page, including other changes that jQuery makes to it (such as inserting and removing elements, ie using .html() method), not the page as it was loaded from the server. jQuery在页面的当前DOM结构上进行操作,包括jQuery对其进行的其他更改(例如,插入和删除元素,即使用.html()方法),而不是从服务器加载页面时进行的更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM