2011-07-20 40 views
0

我有以下代碼:的OnClientClick執行,然後在頁面回發立即

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

我認爲你需要消除事件。

onclick="yea();return false;" 

可能會這樣做。

+1

雖然給你添加到以前的人試圖回答這可能不會做你想要的。在這種情況下,您可能需要在yea()中通過javascript提交表單。 –

+0

我想你是對的。你在這裏給出的解決方案是無效的。它會觸發一個帖子,但是,我的服務器端代碼不會執行..:/任何建議?順便說一句,感謝您花時間回答我的問題馬克 – Dragan

+0

我認爲,常見的做法是功能是(電子){/ *用戶代碼*/e.preventDefault();} onclick =「是(事件);」 –