On document.ready
我有一个函数,它收集具有“wordNum”属性的 html 控件,我发出一个 AJAX 请求,该请求返回每个控件的一些描述,然后我设置这些控件及其innerhtml
带有返回描述的属性。
问题是,如果用户单击后退按钮,这个功能当然不会被执行,但我需要它。
Code:
$(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
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)