簡體   English   中英

將外部html的DIV內容移動到另一個文件的Div

[英]Moving DIV content of an external html to Div of another file

我有3個html文件。 Index.html調用chat.html。 Chat.html主體包含一個DIV,我想用第三個HTML文件(star.html)的Div填充該DIV,該文件與chat.html駐留在同一文件夾中。

chat.html-

  <body> <div id="wrap"> <nav class="navbar navbar-default" role="navigation"> <div class="navbar-header text-center"> <a href="#" class="navbar-brand">Chat - Group Menu</a> </div> </nav> <!-- Begin page content --> <div class="container" id="chatDiv"> <div class="page-header"> <h1>Mobile Layout</h1> </div> <p class="lead">Chat stuff to appear here</p> </div> </div> <div id="testDIV"></div> <div id="footer"> //some DIV content here </div> </body> 

star.html-

 <body> <p> hello all </p> </body> 

我正在使用的jQuery代碼(在外部.js文件中)是-

 $(document).ready(function() { $("#stars").click(function() { alert("change DIV to show STAR stuff"); $("#testDIV").load('star.html'); }); }); 

在此顯示警報。 但是內容並沒有移到chat.html Div。

我在這里想念什么?

就像您正在打開一個新的聊天窗口一樣,您需要尋址該窗口才能操作該DOM。 如果您尚未將jQuery添加到chat.html頁面,則可能需要

    $('#loginBtn').click(function() {
      $(this).validateEmail(); 
      $(this).validatePassword(); 
      var window.popup =  window.open("html/chat.html"); 
    });

 $("#stars").click(function() {
     alert("change DIV to show STAR stuff");
     window.popup.document.$("#testDIV").load('star.html');
 });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM