2013-11-20 78 views
-2

當我點擊按鈕顯示消息時,我得到一個正常的MessageBox,但是當我爲SCOND時間調用Jquery對話框時,我得到兩個MessageBoxs!當我第三次打電話給Jquery Dialog時,我得到三個MessageBoxs!請幫幫我!與asp.net的jquery對話框

這裏是我的代碼:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> 

<!DOCTYPE html> 

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
    <title></title> 

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> 
    <script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.9/jquery-ui.js" type="text/javascript"></script> 
    <link href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.9/themes/start/jquery-ui.css" 
     rel="stylesheet" type="text/css" /> 
    <script type="text/javascript"> 
     $(document).ready(function() { 
      $("[id*=Call_Dialog]").click(function() { 

       $("#MyDiv").dialog({ 
        title: "jQuery Dialog Popup", 
        buttons: { 
         Close: function() { 
          $(this).dialog('close'); 
         } 
        } 
       }); 

       $("#ShowMessage").click(function() { 
        event.preventDefault(); 
        alert('Hi'); 
        $("#MyDiv").dialog('close'); 
       }) 
      }) 
     }); 
    </script> 

</head> 
<body> 
    <form id="form1" runat="server"> 
    <div id="MyDiv" style="display: none"> 

<asp:Button ID="ShowMessage" runat="server" Text="Button" /> 

    </div> 



    </form> 
    <p> 
     <input id="Call_Dialog" type="button" value="button" /></p> 
</body> 
</html> 
+0

你'.dialog()'和'。點擊()''裏面$( 「[ID * = Call_Dialog]」)點擊()'事件。這是你的意思嗎? – erdinger

+0

不,問題是當我打電話給SCOND的Jquery對話框時,我得到兩個MessageBoxs!當我第三次打電話給Jquery Dialog時,我得到三個MessageBoxs! – Lucy

+0

這個問題與ASP.NET無關,只是你知道的。 –

回答

1

謝謝,但我怎麼能叫有按鈕的對話框中,單擊?

對話框應該不會每次點擊的東西和再生

解決方案的時間只有一次初始化放在對話框初始化點擊之外,大功告成

$(document).ready(function() { 

    $("#MyDiv").dialog({ 
       title: "jQuery Dialog Popup", 
       buttons: { 
        Close: function() { 
         $(this).dialog('close'); 
        } 
       } 
      }); 

$("[id*=Call_Dialog]").click(function() { 
    $("#ShowMessage").click(function() { 
       event.preventDefault(); 
       alert('Hi'); 
       $("#MyDiv").dialog('close'); 
      }) 
     }) 
    }); 

打開jQuery的對話框:使用此超載:

$("#MyDiv").dialog('open'); 
+0

它工作正常!謝謝soooooo多!上帝祝福你! – Lucy

+0

@Lucy標記爲已接受的答案 –