大佬教程收集整理的这篇文章主要介绍了jquery – ajax请求后的HTML Anchor标记重定向链接,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
<div class="SELEctNode" id="SELEctNode_1" style="color: rgb(229,229,229); BACkground-color: rgb(47,47,47); "> <a href="http://www.google.com" class="SELEctAnchor" style="color: rgb(229,229); "> Google </a> <img class="childImage" src="icon.png"> </div>
在jQuery中,我有:
$(".SELEctAnchor,.menuAnchor").click(function(event){ event.stopPropagation(); console.log(event.target.nodeName); //event.preventDefault(); $.ajax({ type: 'POST',url: 'http://localsite/menuRedirect.PHP',data: {id:0,module:'Module',source:'source'},complete: function(data){ console.log("DONE"); return true; } }); });
链接重定向到所选页面,但ajax代码永远不会完成,因此永远不会注册用户的点击.
我尝试使用event.preventDefault,但无法恢复已取消的事件.
问题的一部分来自额外的功能,比如,大多数用户右键单击锚标签以在新选项卡中打开(或使用控制点击,或中键单击),并使用类似的东西
<a href="javascript:saveClick(o)">Google</a>
不允许在网站上(出于安全原因).
有什么建议可以做到这一点?
$(".SELEctAnchor,.menuAnchor").click(function(event){ event.preventDefault(); console.log(event.target.nodeName); var self = this; $.ajax({ type: 'POST',complete: function(data){ console.log("DONE"); LOCATIOn.href = self.href; } }); });
或者使用COntext属性删除var self = this
$(".SELEctAnchor,.menuAnchor").click(function(event){ event.preventDefault(); console.log(event.target.nodeName); $.ajax({ type: 'POST',context: this,complete: function(data){ console.log("DONE"); LOCATIOn.href = this.href; } }); });
以上是大佬教程为你收集整理的jquery – ajax请求后的HTML Anchor标记重定向链接全部内容,希望文章能够帮你解决jquery – ajax请求后的HTML Anchor标记重定向链接所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。