html調用html的方法
html中引入調用另一個html的方法,嘗試了好幾種,都列出來:
其中第一種是最好的,其他的方法,可以嘗試看看,是不是適合你當前項目
一、div+$(“#page1”).load(“b.html”)
需要保持結構層次和服務
參考代碼:
<body> <div id="page1"></div> <div id="page2"></div> <script> $("#page1").load("page/Page_1.html"); $("#page2").load("page/Page_2.html"); </script> </body>
二、iframe
參考代碼:
<head> </head> <body> <div id="page1"> <iframe align="center" width="100%" height="170" src="page/Page_1.html" frameborder="no" border="0" marginwidth="0" marginheight="0" scrolling="no"></iframe> </div> <div id="page2"> <iframe align="center" width="100%" height="170" src="page/Page_2.html" frameborder="no" border="0" marginwidth="0" marginheight="0" scrolling="no"></iframe> </div> </body>
三、object引入
參考代碼:
<body> <object style="border:0px" type="text/x-scriptlet" data="page/Page_1.html" width=100% height=150> </object> </body>
四、import引入
測試用
參考代碼:
<head> <link rel="import" href="page/Page_1.html" id="page1"> </head> <body> <script> console.log(page1.import.body.innerHTML); </script> </body>
綜上所訴iframe和object方法最好,有童鞋感覺iframe不能操作到父頁面的跳轉操作,是可以的,加上頂層判斷就好
a標簽的頂層判斷就是top屬性
js的頂層要去parent找百度一下都很多的