我已成功通过vb生成产品列表作为复选框,并将其添加到<ul>
代码
<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;Pwd=master!!@"
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没有识别我动态生成的html
$('document').ready(function () {
$('#weSearch').on('click', function () {
var counted = 0;
var boxes = $('#ulVal').find(':checkbox');
boxes.each(function () {
counted++ ;
});
alert(counted);
});
});
我得到的结果总是0而不是实际的产品数量。我该如何解决这个问题?
答案 0 :(得分:0)
我解决了这个问题,原来我不得不看一下生成的html。由于标签容器,ul
的ID正在发生变化。谢谢你的帮助