jquery mobile click()on listview [英] jquery mobile click() on listview
问题描述
我在jQuery移动的listview有一个问题。我想从服务器使用JSON加载一些数据,并填充你的listview项目。这工作正常。但是当我试图对一个新的加载项的点击反应,我做网得到的事件!
我在 http://jsfiddle.net/VqULm/227/
当您点击某个项目的点击事件时不再跟踪。
非常感谢您阅读!
尝试
$('#listview' 'li',function(){
alert(Works); //通过直接访问DOMElement属性获得点击的li的ID)
}
与 jQuery> 1.7
$('#listview li')。live('click',function(){
alert(Works); //通过直接访问DOMElement属性
} ;您的jQuery版本为1.6.4。
为什么需要此
因为。您在页面重新加载后在 listview
中添加 li
,所以 li
s live
(对于您使用的jQuery版本)或 delegate
(jQuery> 1.7)。
I have a problem with the listview in jquery mobile. I want to load some data from a server using JSON and fill thy listview with the items. That works fine. But when I am trying to react on a click on a new loaded item I do net get the event! I think I have to refresh the view somehow, bit do not know how.
I made a little sketch on http://jsfiddle.net/VqULm/227/
when u hit the click me button the click event on a item isn't tracked anymore. How do i get the "Wokrs" alert on the new items?
Thank u very much for reading!
Try
$('#listview').on('click', 'li', function() {
alert("Works"); // id of clicked li by directly accessing DOMElement property
});
with jQuery > 1.7
OR
$('#listview li').live('click', function() {
alert("Works"); // id of clicked li by directly accessing DOMElement property
});
with your jQuery version 1.6.4.
why you need this
Because. you're adding li
within listview
after page reload, so any event for those li
s should live
(for jQuery version you used) or delegate
(jQuery > 1.7).
这篇关于jquery mobile click()on listview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!