Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 列表视图的索引_Jquery_Html_Jquery Mobile_Jquery Plugins - Fatal编程技术网

Jquery 列表视图的索引

Jquery 列表视图的索引,jquery,html,jquery-mobile,jquery-plugins,Jquery,Html,Jquery Mobile,Jquery Plugins,追加是正确的,其填充listview。我想要的是在单击每个listview时获取其填充的索引。但在我的提醒消息中,它总是0索引。如何获取每个listview的索引?谢谢 Html代码 <ul id="RecipeList" data-role="listview" data-split-icon="star" data-split-theme="a" data-inset="true "href="#recpdetail"> </ul>

追加是正确的,其填充listview。我想要的是在单击每个listview时获取其填充的索引。但在我的提醒消息中,它总是0索引。如何获取每个listview的索引?谢谢

Html代码

<ul id="RecipeList" data-role="listview" data-split-icon="star" data-split-theme="a" data-inset="true "href="#recpdetail">                 
</ul>

这里的问题是您总是得到第一个
li
元素的索引,而不是单击的
li

将单击事件更改为针对
li
中的
RecipeList
元素,如下所示

$("#RecipeList").on('click', 'li', function(){
    var selected_index = $(this).index();
    alert('Selected Index = ' + selected_index);
});  
$("#RecipeList").click(function(){
    var selected_index = $(this).find('li').index();
    alert('Selected Index = ' + selected_index);
});      
$("#RecipeList").on('click', 'li', function(){
    var selected_index = $(this).index();
    alert('Selected Index = ' + selected_index);
});