Jquery mobile 如何获取ListView JQUERYMOBILE中所选元素的索引
我创建了一个动态的Jquery mobile 如何获取ListView JQUERYMOBILE中所选元素的索引,jquery-mobile,Jquery Mobile,我创建了一个动态的列表视图,其中有一个链接id=“a” 我需要基于此的索引号,我需要加载动态XML 请帮我解决这个问题 谢谢 希亚姆 下面是一个演示: 这将事件处理程序绑定到单击事件的#accpmenu列表中的列表项,该事件查找单击列表项的索引(与其他列表项元素相比) 另一方面,您的代码中似乎有一些无效的HTML: $("#accpmenu").append('<li><a href='+ "#" + ' id="a" ">'+ this.textContent +'&l
列表视图
,其中有一个链接id=“a”
我需要基于此的索引号,我需要加载动态XML
请帮我解决这个问题
谢谢
希亚姆
下面是一个演示:
这将事件处理程序绑定到单击
事件的#accpmenu
列表中的列表项,该事件查找单击列表项的索引(与其他列表项元素相比)
另一方面,您的代码中似乎有一些无效的HTML:
$("#accpmenu").append('<li><a href='+ "#" + ' id="a" ">'+ this.textContent +'</a> </li>');
请注意,.on()
在jQuery 1.7中是新的,在上述情况下,它将替换.delegate()
(来自早期版本)
以下是一些文档,供您帮助解释上述示例:
:.on()
:.index()
:.parents()
$("#a").live("click",function(e)
{
//What should i write here to get the selected index?.
}
$('#accpmenu').on('click', ' > li', function () {
var selected_index = $(this).index();
});
$("#accpmenu").append('<li><a href='+ "#" + ' id="a" ">'+ this.textContent +'</a> </li>');
$("#accpmenu").append('<li><a href='+ "#" + ' id="a">'+ this.textContent +'</a> </li>');
$('#accpmenu').on('click', 'a', function () {
//this gets the index by finding the first parent list-item element and getting it's index compared do its siblings
var selected_index = $(this).parents('li').eq(0).index();
});