簡體   English   中英

在后退按鈕上單擊執行功能。

[英]On back button click execute a function.

document.ready事件上,我有一個函數收集具有屬性“wordNum”的 html 控件,然后我發出一個 AJAX 請求,該請求返回每個控件的一些描述,然后我設置這些控件及其innerhtml屬性返回的描述。

問題是如果用戶點擊后退按鈕,這個功能當然不會執行,但我需要那個。

代碼:

$(document).ready(function () {
    Translate();
});
function Translate() {
    var list = new Array();
    $("*[wordNum]").each(function () {
        var endRes = {
            ControllerName: this.id,
            WordNumber: this.getAttribute("wordNum")
        };
        list.push(endRes);
    });
    jQuery.ajax({
        url: ' @Url.Action("Translate")',
        contentType: "application/json",
        dataType: "json",
        data: {
            List: JSON.stringify(list)
        },
        traditional: true,
    }).done(function (data) {
        $.each(data, function (key, val) {
            $("*[wordNum]").each(function () {
                if (this.id == val.ControllerName) {
                    this.innerHTML = val.Description;
                }
            });
        });
    });
}

那么我怎樣才能讓后退按鈕點擊再次執行這個功能Translate

您可以使用 popstate 事件來觸發事件:

$(window).on("popstate", function (event, state) {
    // Here comes the code to execute when the back button is pressed
}

暫無
暫無

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

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