c#
  • jquery
  • asp.net
  • 2013-10-14 40 views 1 likes 
    1

    我試圖運行要在服務器端訪問的一段jQuery代碼時出現錯誤。該錯誤是在無功HTML當添加html時,服務器標記形成不當很好

    的錯誤是:

    分析器錯誤信息:服務器標記的格式不正確。

    $("#add_group").click(function (e) { 
           var html = '<input id=\"newGroup\" placeholder=\"Group Name\" runat=\"server\" ><button id=\"Save_Group\" type=\"button\" runat=\"server\" onserverclick=\"saveGroupClick_Handler\" >Save</button><ul class=\"sortable\"></ul>'; 
           $(html).insertBefore($(".sortable:first")); 
    
          }); 
    

    人有任何想法如何解決這個問題?

    回答

    2

    您可以不是使用javascript創建服務器標記。您可以使用asp.net在服務器端創建標記,在服務器上將其隱藏爲javascript/jQuery或將其Style設置爲display:none,並在客戶端和服務器端對其進行訪問。

    Asp.net服務器控件

    <asp:TextBox id="textbox1" runat="server" style="display:none" ></asp:TextBox> 
    

    OR

    <input type="text" id="textbox1" runat="server" style="display:none" /> 
    

    的Javascript

    $("#add_group").click(function (e) { 
        var textbox1 = $('#<%= textbox1.ClientID %>'); 
        textbox1.insertBefore($(".sortable:first")); 
        textbox1.show(); 
    }); 
    
    相關問題