2014-10-22 102 views
0

我能夠成功地生成的產品列表通過VB和添加這些複選框<ul>標籤jQuery的不能識別動態創建的元素

<input type="text" id="searchText" /> 
<input type="button" value="Search" id="weSearch" /> 
<div>                      
<ul runat="server" id="ulVal" style="list-style-type:none"/></ul>      
</div> 

Dim brandname As String 
     Dim brandid As Integer 
     Dim build As New StringBuilder() 
     Dim msql As New MySqlConnection() 
     msql.ConnectionString = "Server=192.168.1.230;Database=cable_tv_reporting1;Uid=root;[email protected]" 
     msql.Open() 
     Select Case msql.State 
      Case System.Data.ConnectionState.Open 

       Exit Select 
      Case System.Data.ConnectionState.Closed 

       Response.Write("Connection Closed") 
       Exit Select 
      Case Else 
       Exit Select 
     End Select 
     Dim cmd As New MySqlCommand("select brandID, brandName from cap_brand where isActive=1;", msql) 
     Dim reader As MySqlDataReader = cmd.ExecuteReader() 
     While reader.Read() 
      brandid = Convert.ToInt32(reader(0)) 
      brandname = reader(1).ToString() 
      build.Append("<li><input type='checkbox' name ='brands' id='" & brandid & "' value='" & brandid & "'/><label for='" & brandid & "'>" & brandname & "</label></li>") 

     End While 
     ulVal.InnerHtml = build.ToString() 

問題jQuery不會recongize的HTML,我已動態生成

$('document').ready(function() { 
                                $('#weSearch').on('click', function() { 
                                 var counted = 0; 
                                 var boxes = $('#ulVal').find(':checkbox'); 
                                 boxes.each(function() { 
                                  counted++ ; 
                                 }); 
                                 alert(counted); 
                                }); 
                               }); 

我得到的結果始終爲0而不是實際的產品數量。我該如何解決這個問題

+1

您應該粘貼生成的HTML,並可能刪除您的數據庫的root密碼 – 2014-10-22 05:43:19

+1

您是否遇到任何控制檯錯誤? – 2014-10-22 05:47:26

+0

我得到2個錯誤,但我似乎無法弄清楚如何查看錯誤是什麼。使用jquery調試器 – 2014-10-22 05:56:01

回答

0

我解決了這個問題,結果我必須看看生成的html。由於選項卡容器,ul的ID正在改變。感謝您的幫助

相關問題