我在服务器端创建了一个ul
列表,如下所示。我想用 jquery 向a
元素添加点击事件,但我无法访问任何元素。这是我的代码:
服务器端:
StringBuilder sbSubCitchens = new StringBuilder();
sbSubCitchens.Append(@"<div id=""content_1"" class=""subCats"">");
sbSubCitchens.Append("<ul>");
foreach (kitchen kitchen in kitchenList)
{
sbSubCitchens.Append(@"<li><a class="" " + kitchen.KitchenId + @""">" + kitchen.Name + "</a> </li>");
}
sbSubCitchens.Append("</ul>");
sbSubCitchens.Append("</div>");
ltrKitchenList.Text = sbSubCitchens.ToString();
Javascript:
$(document).ready(function () {
$(".mCSB_container ul li a").click(function () {
// do smth...
});
})
html输出:
<div class="mCSB_container" style="position: relative; top: 0px;">
<ul>
<li><a class=" 1">Cafe</a> </li>
<li><a class=" 2">Dünya Mutfağı</a> </li>
</ul>
</div>