简体   繁体   English

您可以使用js在其他人内部切换html页面吗?

[英]Can you switch html pages inside others using js?

https://www.w3schools.com/js/tryit.asp?filename=tryjs_dom_image this is about changing html content with js, but it is about images. https://www.w3schools.com/js/tryit.asp?filename=tryjs_dom_image这是关于用js更改html内容,但它是关于图像的。 is it possible to do something like this too, so the same but doing it with a new html file so that you can switch pages inside a page? 是否有可能做类似的事情,所以做同样的事情,但是用一个新的html文件来做,以便您可以在页面内切换页面? So the plan is to replace the html underneath (with id="id") by another html file using js. 因此,计划是使用js用另一个html文件替换下面的html(具有id =“ id”)。

 document.getElementById("id").src = "otherfile.html"; 
 <html> <body> hey guys! here is my html page. If you click underneath, content will be changed. <html id="id"> <body> here is the text that will change if id="id" will be changed by a different html file </body> </html> </body> </html> 

Of course, I know that this won't work. 当然,我知道这行不通。 But is there a way to archieve this? 但是有办法存档吗?

Thank you if you are reading and trynna answer my post, I understand if it's a messy and shitty question so shoutout to you. 谢谢,如果您正在阅读并尝试回答我的帖子,我知道这是一个麻烦而卑鄙的问题,所以向您大喊大叫。

How about changing the contents of a div instead the whole HTML ? 如何更改div的内容而不是整个HTML Via jQuery. 通过jQuery。

<div id="dynamic-html">
    here is the text that will change if id="id" will be changed by a different html file
</div>

$( "#btnChangeHTML" ).click(function() {
    $( "#dynamic-html" ).html("<div  class='myclass'>This is the custom HTML</div>");
});

Here's a fiddle: 这是一个小提琴:

https://jsfiddle.net/u8xsker2/2/ https://jsfiddle.net/u8xsker2/2/

Read about iframe. 了解有关iframe的信息。 Perhaps it is what you want. 也许这就是您想要的。

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

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