点击事件jQuery,li标签中的href(jquery on click event, a href within li tag)
我有以下列方式填写的UL:
$("#dropdownFloorplanGroups").append("<li><a href='#'>" + value.Name + "</a></li>");这在我的浏览器上正确显示
然而,我似乎无法启动点击事件,然后提醒我在<li></li>设置的名称
我试过这个,但没有被解雇。
$('li a').click(function (e) { alert($(this).find("a").text()); });jquery点击事件应该是什么?
I have a UL which I populate in the following way:
$("#dropdownFloorplanGroups").append("<li><a href='#'>" + value.Name + "</a></li>");This displays correctly on my browser
However I can't seem to fire off the click event, which then alerts the name that I have set in the <li></li>
I tried this, but nothing gets fired.
$('li a').click(function (e) { alert($(this).find("a").text()); });What should the jquery click event be?
最满意答案
你必须使用事件委托:
$('#dropdownFloorplanGroups').on('click', 'li a', function(e) { alert($(this).text()); });$('li a')不会考虑新创建的元素。
You have to use event delegation:
$('#dropdownFloorplanGroups').on('click', 'li a', function(e) { alert($(this).text()); });$('li a') won't take into account the newly created elements.
更多推荐
发布评论