我有两个链接index.html到target.html.
第一个链接很简单.它只是去target.html.
但我想用第二个链接做点别的事.
只是:
1位用户点击指向target.html的第二个链接
2 - 不仅target.html出现,而且show-this-page-in-target.html-if-user-clicks-the-second-link.html在.page-classjQuery load()函数的帮助下也出现在元素中.
到目前为止我能做些什么?
当我在target.html中时,我可以使用以下代码加载我想要的页面:
HTML
<a href="#" id="load" class="btn btn-primary">Load</a>
Run Code Online (Sandbox Code Playgroud)
JavaScript的
<script type="text/javascript">
$('#load').click(function(){
$('.page-class').load('show-this-page-in-target.html-if-user-clicks-the-second-link.html .target-class')
});
</script>
Run Code Online (Sandbox Code Playgroud)
但是当我通过链接访问该页面时,我不知道如何加载它们.
这是你taget.html的第二个链接:
<a href="target.html#load" class="btn btn-primary">Load</a>
Run Code Online (Sandbox Code Playgroud)
在target.html中使用此代码:
<script>
if(window.location.hash === '#load') {
$(function() {
$('.page-class').load('show-this-page-in-target.html-if-user-clicks-the-second-link.html .target-class')
});
}
</script>
Run Code Online (Sandbox Code Playgroud)
应该管用.
| 归档时间: |
|
| 查看次数: |
64 次 |
| 最近记录: |