2012-11-16 50 views
0

我正在使用jQuery創建一個對話框,其中包含名爲「dialog-tatto」的div的內容。 但由於某種原因,它不會工作。 這是我當前的代碼:div.dialog()不會生成對話框

var button = $(".ui-dialog-buttonpane button:contains(\"New\")"); 
    $(button).show(); 
    button = $(".ui-dialog-buttonpane button:contains(\"Update\")"); 
    $(button).hide(); 
    $("#dialog-tattoo").dialog("open"); 

,這是我的div:

  <div id="dialog-tattoo"> 
      <table> 
       <tr> 
        <td> 
         <asp:Label ID="lblPersonMarkType" runat="server" Text="Mark type:" meta:resourcekey="lblPersonMarkTypeResource1" /> 
         <asp:DropDownList ID="ddlPersonMarkType" Width="120px" runat="server" AppendDataBoundItems="True" 
          DataSourceID="dsPersonMarkType" DataTextField="ScarTattooName" DataValueField="ScarTattooTypeID" 
          OnPreRender="ddl_PreRender" meta:resourcekey="ddlPersonMarkTypeResource1"> 
          <asp:ListItem Value="-1" meta:resourcekey="ListItemResource1">--Select--</asp:ListItem> 
         </asp:DropDownList> 
        </td> 
        <td> 
         <asp:Label ID="lblPersonBodyLocation" runat="server" Text="Body Location:" meta:resourcekey="lblPersonBodyLocationResource1" /> 
         <asp:DropDownList ID="ddlPersonBodyLocation" Width="120px" runat="server" AppendDataBoundItems="True" 
          DataSourceID="dsPersonBodyLocation" DataTextField="BodyLocation" DataValueField="BodyLocationID" 
          OnPreRender="ddl_PreRender" meta:resourcekey="ddlPersonBodyLocationResource1"> 
          <asp:ListItem Value="-1" meta:resourcekey="ListItemResource1">--Select--</asp:ListItem> 
         </asp:DropDownList> 
        </td> 
       </tr> 
       <tr> 
        <td colspan='2'> 
         <asp:Label ID="lblPersonMarkDescription" runat="server" Text="Description:" meta:resourcekey="lblPersonMarkDescriptionResource1" /> 
         <asp:TextBox ID="txtPersonMarkDescription" runat="server" Height="40px" TextMode="MultiLine" 
          Width="400px" meta:resourcekey="txtPersonMarkDescriptionResource1" /> 
        </td> 
       </tr> 
      </table> 
     </div> 

回答

2

使用此

$("#dialog-tattoo").dialog(); 

代替

$("#dialog-tattoo").dialog("open"); 

DEMO

更新:(帶標題)

$("#dialog-tattoo").dialog({ 
    title:'This is my Title' 
}); 

DEMO

更新:(對於動態按鈕)

$("<div/>",{ 
    'text':'Button', 
    'id':'btn1', 
    'class':'myBtn', 
    'style':'margin:5px;color:green;' 
}).button().appendTo('body'); 

DEMO

+0

這有效,但那我該如何改變標題? – john

+0

你可能會解釋爲什麼jquery的其他部分不起作用嗎?就像它想要創建的按鈕一樣 – john