作者:exu8145079 | 来源:互联网 | 2023-12-12 15:59
I have the following on html
我在html上有以下内容
I am trying to get write a function to handle the event when any of the list element get clicked. But it doesn't seems to be triggering at all when I click on the
element.
我试图编写一个函数来处理任何列表元素被点击时的事件。但是当我点击
元素时,它似乎根本没有触发。
$('#addressList').on('click', 'li', function() {
alert("clicked");
alert( $(this).text() );
});
The
elements are created dynamically through this code:
元素是通过以下代码动态创建的:
listCOntents= $("" + addresses[i].lable + "");
jQuery('#addressList').append(listContents);
And I verified through my browser's console that they are being created correctly as such
我通过浏览器的控制台验证了它们是否正确创建
outerHTML: "6 Cashew Crescent
6 Cashew Crescent. (S)679751"
Let's ignore about the dynamic list first. The thing is even my static list element are not responding to the event handler upon click. Have been trying to figure out the problem for a couple of hours now..
我们先忽略动态列表。甚至我的静态列表元素在点击时没有响应事件处理程序。一直试图找出问题几个小时了..
I have created a jsfiddle for my static li element not working https://jsfiddle.net/tmu50t9z/
我为我的静态li元素创建了一个jsfiddle不工作https://jsfiddle.net/tmu50t9z/
jsfiddle to my whole code > https://jsfiddle.net/8wwnx64x/
jsfiddle to my code> https://jsfiddle.net/8wwnx64x/
2 个解决方案