我不太确定我是否没有在正确的范围内使用它或什么,但我有一个脚本,它基本上捕获链接单击并导致页面在转到链接页面之前淡出。但是,如果链接是 JavaScriptonclick,脚本失败。
这是我的代码:
<script type="text/javascript">
pageObj = {
init: function(){
$("body").fadeTo("slow", 1);
},
redirectPage: function(redirect){
window.location = redirect;
},
linkLoad: function(location){
$("body").fadeOut(1000, this.redirectPage(location));
}
};
$(document).ready(function() {
pageObj.init();
$("a").click(function(e){
e.preventDefault();
if (this.attr('onclick') !== undefined) {
eval(this.attr('onclick').val());
} else {
var location = this.href;
pageObj.linkLoad(location);
}
});
});
</script>
正如您所看到的,我正在尝试检查该链接是否具有onclick属性,然后调用onclick函数(如果存在)。我怎样才能实现这个目标?
Use: $(this).attr
代替this.attr
这迫使它进入 jQuery 的上下文。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)