我阻止了超链接上的一些 native 点击事件,以检查结果页面是否包含内容。
我正在保存 jquery 事件对象,经过一些检查后,我想让事件以自然的方式进行。
- 捕获事件
- 检查内容
- 如果内容可用
- 转发事件,因为它被触发
- 其他
- 什么也不做
此时,我只是保存 "href"
属性,并希望在返回 true 时将其设置为 document.location.href
。
现在的问题是:是否有比将 href 设置为 document.location.href
更好的方法来转发/重新引发现有事件?
最佳答案
使用 document.location.href
就可以了,而且对我来说似乎也是最简单的选择。
但只是为了探索其他选项,如果认为安全,您也可以让 js 为您单击该链接。例如,类似这样的事情。
$('a').click(function() {
if( !$(this).is('.content-verified') ) {
var self = this;
// Do your content checking here, with the callback for verified good
// content being $(self).has_good_content();
return false;
}
return true;
});
// Callback for good content
// should be something like this:
$.fn.has_good_content = function() {
return $(this).each(function() {
$(self).addClass('content-verified');
$(self).click();
});
};
关于javascript - js jquery 转发保存的事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5363525/