簡體   English   中英

jQuery-重定向到頁面后更改頁面的屬性

[英]jQuery - change attribute of a page after being redirected to it

因此,我正在制作一個wordpress網站,因此,我希望將自定義JavaScript保持在最低水平。 基本上,我有Page1和Page2,每個都有幾個子頁面。 在Page1子級中,有指向Page2子級的鏈接。 Page2子級中有一個“后退”按鈕,當前僅可導航到Page2。 我要完成的工作是:如果將Page2-child從Page1-child導航到,則要將“后退”按鈕的href設置為從其導航的頁面。 到目前為止,這是我得到的:

jQuery(document).ready(function($){

    $('.application-button').on('click', function(event){
        event.preventDefault();
        var currURL = window.location;
        window.location.href = event.currentTarget.href;
        $('.dynamic-link').attr('href', currURL); //<-- .dynamic-link is a class of the Back button
        //I figured that if it came after the window.location change, it would still be called

    });

});

很抱歉,如果很難遵循代碼之前的說明,但是由於它對工作敏感,因此我無法真正進行更詳細的說明。

任何和所有幫助表示贊賞!

一個好的方法是導航到javascript的最后一頁

<script>
function goBack() {
    window.history.back()
}
</script>

<body>
<button onclick="goBack()">Go Back</button>
</body>

http://www.w3schools.com/jsref/met_his_back.asp

在您的情況下:

$('.application-button').on('click', function(event){window.history.back();});

暫無
暫無

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

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