onClientClick执行,然后立即回发页面

时间:2011-07-20 21:54:03

标签: jquery asp.net frontend

我有以下代码:

functions.js =>

function loadPopup() {
    $("#backgroundPopup").css({
        "opacity": "0.7"
    });
    $("#backgroundPopup").fadeIn("slow");
    $("#popupContact").fadeIn("slow");
}

//disabling popup with jQuery magic!  
function disablePopup() {
    $("#backgroundPopup").fadeOut("slow");
    $("#popupContact").fadeOut("slow");
}

//centering popup  
function centerPopup() {
    //request data for centering  
    var windowWidth = document.documentElement.clientWidth;
    var windowHeight = document.documentElement.clientHeight;
    var popupHeight = $("#popupContact").height();
    var popupWidth = $("#popupContact").width();
    //centering  
    $("#popupContact").css({
        "position": "absolute",
        "top": windowHeight / 2 - popupHeight / 2,
        "left": windowWidth / 2 - popupWidth / 2
    });
    //only need force for IE6  

    $("#backgroundPopup").css({
        "height": windowHeight
    });

}

function no() {
    return false;
    disablePopup();
}

function yea() {
    $('#form1').submit(function () {
        return true;
    })
}

$(function () {
    $("#popupContactClose").bind('click', function () {
        disablePopup();
    });
});

function yeah() {
    $(this).bind('click', function (event) {

        centerPopup();

        loadPopup();

    });
}

...以及以下标记:

<body>
    <form id="form1" runat="server">
    <asp:Button ID="btn1" runat="server" OnClientClick="yeah();" Text="Click me!" />
    <div id="popupContact">
        <a onclick="xClick()" id="popupContactClose">x</a>
        <input type="submit" onclick="yea()" value="Yes" />
        <input type="button" onclick="no()" value="No" />
    </div>
    <div id="backgroundPopup">
    </div>
    </form>
</body>
</html>

问题是OnClientClick事件调用yea(),div显示然后立即消失并且页面回发。这很奇怪。你能帮帮我吗?提前谢谢!

1 个答案:

答案 0 :(得分:1)

我认为你需要扼杀这个事件。

onclick="yea();return false;"

可能会这样做。

相关问题