使用标签替换div [英] using a tag to replace div

查看:110
本文介绍了使用标签替换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();">

这篇关于使用标签替换div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆