覆盖点击事件无效

时间:2015-04-03 21:43:36

标签: javascript jquery

我正在尝试覆盖following domain上的某些点击事件,但它无法正常工作。在按下呼叫按钮后,它将打开一个对话框,其中有一个应用按钮我想在点击该按钮时去其他网站,现在它在点击该按钮后打开另一个对话框。我使用以下代码来覆盖click事件,但它不起作用。

    <!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="UTF-8" />
<title>My Website</title>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script type='text/javascript'>
/* <![CDATA[ */
var soload = {"lang":"en","dir":"LTR","cookieOptions":{"domain":".hellobrokers.com"},
        "packages":{"Clock":{},
        "RegularPlatform":{"settings":{"selector":"#so_container"}}
}};
/* ]]> */
</script>
<script type='text/javascript' src='//spotplatform.hellobrokers.com/SpotOptionPlugin.js?ver=4.1.1'></script>
<script type="text/javascript">SO.load(soload);
</script>
<script>(function() {
var _fbq = window._fbq || (window._fbq = []);
if (!_fbq.loaded) {
var fbds = document.createElement('script');
fbds.async = true;
fbds.src = '//connect.facebook.net/en_US/fbds.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(fbds, s);
_fbq.loaded = true;
}
})();
window._fbq = window._fbq || [];
window._fbq.push(['track', '6022904954366', {'value':'0.01','currency':'EUR'}]);
</script>
</head>
<body>
<div id="bgbanner">
    <div id="index">
        <div class="mainContent">
            <div id="so_container">
                <div align="center" class="please_wait"> 
                <img border="0" src="img/ajax-loader.gif" alt="" /><br />
                    <br />
                    Please Wait<br />
                    <br />
                    Loading</div>
            </div>
        </div>
    </div>
</div>

<script>
    $(document).ready(function() {
        $('.applyApprove').unbind();

        $(".applyApprove").click(function() {
            window.location = 'http://www.google.com';
        });
    });
</script>
</body>
</html>

2 个答案:

答案 0 :(得分:1)

而不是.unbind(),请使用.off('click'),它应该有效:

<script>
    $(document).ready(function(){
         $("button.applyApprove").off('click');

         $("button.applyApprove").click(function(){
            window.location = "http://www.google.com";
         });
    });
</script>

答案 1 :(得分:0)

只需使用$('.applyApprove')代替$('button.applyApprove')(请注意没有button):

<script>
    $(document).ready(function() {
        $('.applyApprove').unbind();

        $(".applyApprove").click(function() {
            window.location = 'http://www.google.com';
        });
    });
</script>