[英]How do I execute a jQuery function on page load if and only if the page is accessed via a specific hyperlink?
[英]How to apply jQuery's load() function on page if I go to page via specific link
我在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-class
元件與jQuery的幫助load()
功能。
到目前為止,我能做什么?
當我已經進入target.html時,可以使用以下代碼加載所需的頁面:
的HTML
<a href="#" id="load" class="btn btn-primary">Load</a>
的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>
但是當我通過鏈接進入該頁面時,我不知道如何加載它們。
這是您指向taget.html的第二個鏈接:
<a href="target.html#load" class="btn btn-primary">Load</a>
在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>
應該管用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.