使用标签替换div

问题描述:

我的网站有2个页面,每个页面都有彼此的超链接,但是当用户单击该超链接时,我只需要将该页面的某个div替换为另一页面上的某个div,请指导我如何对其进行编程.

my site has 2 pages both have hyperlinks to each other but when user click on that hyperlink I just need a certain div of that page to be replaced by certain div on other page, please guide me how to program it.

结构

page1.html

page1.html

<div id="no_replace">
  <a href="page2.html">page 2</a>
  <div id="replace">
    //page one stuff
  </div>
</div>

page2.html

page2.html

<div id="no_replace">
  <a href="page1.html">page 1</a>
  <div id="replace">
    //page two stuff
  </div>
</div>

因此在usr单击链接第二页"时在第一页上...我希望将第一页的替换" div替换为page2.html的替换" div

so on page one when usr clicks on link "page two" ... I want the 'replace' div of page one to be replaced by 'replace' div of page2.html

您需要使用javascript触发一个事件,单击该按钮时将替换div的内容.从w3schools学习一些JavaScript.

you need to use javascript to trigger an event where the content of the div is replace when the button is clicks. Learn some javascript from w3schools.

<script type="text/javascript">
function dosomething(){
 //replace div content here
}
</script>
<a href="somelink" onclick="dosomething();">