TypeError:$(...).unload不是一个函数-JQuery 3.1.0 [英] TypeError: $(...).unload is not a function - JQuery 3.1.0
本文介绍了TypeError:$(...).unload不是一个函数-JQuery 3.1.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在重定向到其他页面之前执行一个函数,但是当加载原始页面时,出现了我在标题中写的错误:
I'm trying to execute a function before redirecting to other page, but when the original page loads I get the error that I wrote in the title:
TypeError: $(...).unload is not a function
我已经尝试过了:
$( window ).unload(function() {
return "Bye now!";
});
这:
$(window).unload(function(){
cambiar_ruta();
alert(ruta);
});
但是没有任何效果,我什至没有收到离开页面"警告.
But nothing is working,I don't even get a Leaving page warning.
使用下一个代码,我没有收到错误,但是该函数从未被触发,并且警报也从未显示:
With next code I don't get an error, but the function is never triggered and the alert never shown:
var ruta;
$(window).bind('onbeforeunload', function(e){
alert('Bye.');
cambiar_ruta();
alert(ruta);
});
我正在使用jquery-3.1.0.min
I'm using jquery-3.1.0.min
推荐答案
请尝试如下更改,因为您使用的是jquery-3
Try to change like below, because you are using jquery-3
$(window).on("unload", function(e) {
alert("call");
console.log("this will be triggered");
});
这篇关于TypeError:$(...).unload不是一个函数-JQuery 3.1.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文