jQuery Mobile的列表视图:更改值单击时 [英] jQuery Mobile List View: Change a Value When Clicked

查看:162
本文介绍了jQuery Mobile的列表视图:更改值单击时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在遇到麻烦措辞我的问题。所以,我在jQuery Mobile的列表视图,它是动态创建的。而不是链接到一个列表项被点击时外部网页,我只是希望能够抓住他们点击的项目的文本。

在我的情况下,它一个名称列表,我想知道他们点击哪一个。我已经创建了HTML名单:

 < D​​IV数据角色=内容的数据主题=B>        < D​​IV ID =friends_list_view级=内容主要数据主题=C>
            < UL数据角色=列表视图数据过滤器=真正的数据主题=C>
            < / UL>
        < / DIV>
    < / DIV>

当点击一个项目,我想用他们所选择的名称来运行一些功能。我该怎么做?

,然后动态地更新以后它:

  VAR listString = NULL;
为(i的session_library){
        listString ='<李>< A HREF =#>'+ session_library [I] ['名'] +'< / A>< /李>';
        $(#friends_list_view UL)追加(listString)。}$(#friends_list_view UL)的列表视图(刷新)。


解决方案

假设你的ListView看起来像这样:

 < UL数据角色=列表视图数据过滤器=真正的数据主题=CID =my_listview>
         <立GT;行A< /李>
         <立GT;行B< /李>
< / UL>

您可以注册一个Click事件处理程序,这将给你的<李方式> 背课文,例如

  $('#my_listview')。代表(礼,点击,函数(){
    警报(this.innerText);
});

修改:更改 V单击点击。请参阅文档

I'm having trouble phrasing my question. So I have a listview in jQuery mobile and it was created dynamically. Rather than link to an outside page when a list item is clicked, I just want to be able to grab the text of the item they clicked.

In my case its a list of names, and I want to know which one they clicked. I've created the list in HTML with:

<div data-role="content" data-theme="b">

        <div id="friends_list_view" class="content-primary" data-theme="c"> 
            <ul data-role="listview" data-filter="true" data-theme="c">
            </ul>
        </div>  
    </div>

When an item is clicked, I want to run some function using the name they have selected. How can I do that?

and then dynamically updated it later with:

var listString = null;
for(i in session_library){
        listString =  '<li><a href="#">'+session_library[i]['name']+'</a></li>';
        $("#friends_list_view ul").append(listString);

}

$("#friends_list_view ul").listview('refresh');

解决方案

Assuming that your listview will look like this:

<ul data-role="listview" data-filter="true" data-theme="c" id="my_listview">
         <li>Row A</li>
         <li>Row B</li>
</ul>

you can register a click event handler which will give you the <li> text back, e.g.

$('#my_listview').delegate('li', 'click', function () {
    alert(this.innerText);
} );    
​

Edit: Changed vclick to click. See the documentation.

这篇关于jQuery Mobile的列表视图:更改值单击时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆