colorbox和防止默认不能一起工作? [英] colorbox and preventdefault not working together?
问题描述
我使用jquery调用一个colorbox,并试图阻止地址改变,但似乎每次都会触发地址更改。这是我目前的代码:
I'm calling a colorbox using jquery and trying to prevent the address from changing but it seems to trigger an address change every time. Here is my current code:
<div style='display:none'>
<div id='send_alert_div' class="wysiwyg_container">
<h2>Contact Us</h2>
....
</div>
</div>
<a class="contact" href="#" >Contact</a>
我的JavaScript代码用于处理联系人的点击事件
$ b $点击(功能(e){
e.preventDefault();
$(。contact))。b
my javascript code to handle the click event for Contact
$(".contact").click(function(e){
e.preventDefault();
$(".contact").colorbox({width:"600px", height: "420px", inline:true, href:"#send_alert_div"});
});
有没有人知道为什么这不起作用?它会在每次点击时触发地址更改。
Does anyone see why this wouldn't work? It triggers an address change every time it's clicked.
推荐答案
我不知道您在说什么地址更改。那必须由你没有包括的一些脚本来控制。此外,colorbox已经应用了e.preventDefault();所以你可以简化上面的代码来简单地这样做:
I don't know what you are talking about with address changes. That must be controlled by some piece of script that you haven't included. Furthermore, colorbox already applies e.preventDefault(); So you could simplify the above code to simply this:
$(".contact").colorbox({width:"600px", height: "420px", inline:true, href:"#send_alert_div"});
您的其他问题听起来没有关系。如果不知道哪些代码导致了您的地址更改,但是如果它是一个简单的事件绑定,您可能可以通过将以上代码替换为以下代码来阻止它: / p>
Your other issue sounds unrelated. It's going to be difficult to instruct you on what to do without seeing what code is causing your 'address change', but if it is a simple event binding, you may be able to prevent it by replacing your above code with the following:
$(".contact").unbind('click').colorbox({width:"600px", height: "420px", inline:true, href:"#send_alert_div"});
这篇关于colorbox和防止默认不能一起工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!