如何在jQuery列表视图中为特定链接创建点击事件。 [英] How to create click event for specific link in a jQuery listview.

查看:70
本文介绍了如何在jQuery列表视图中为特定链接创建点击事件。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个函数,当你点击一个列表视图中的特定链接时开始。
问题在于,当您点击链接时,事件似乎不会触发。该列表是动态创建的。我不确定是否会导致问题。

 < label for =listviewForLastTenCalls>最近十次调用:< / label> 
< ul data-role =listviewid =listviewForLastTenCalls>
< / ul>
< script>
$('#listviewForLastTenCalls li')。click(function(){
// alert('click event handler fired');
< / script>


解决方案


演示



<$ p $ < code>< ul data-role =listviewid =listviewForLastTenCalls>
<! - 项目动态生成 - >
< / ul>

JS
< pre $ $(document).on('click','#listviewForLastTenCalls li a',function(){
// code
});


I'm trying to create a function that starts when you click on a specific link in a listview. The issue is that event doesn't seem to fire when you click the link. The list is created dynamically. I'm not sure if that causes an issue.

    <label for="listviewForLastTenCalls">Last Ten Calls:</label>
    <ul data-role="listview" id="listviewForLastTenCalls">
    </ul>
<script>
   $('#listviewForLastTenCalls li').click(function(){
        //alert('click event handler fired');
</script>

解决方案

Demo

<ul data-role="listview" id="listviewForLastTenCalls">
  <!-- items dynamically generated -->
</ul>

JS

$(document).on('click', '#listviewForLastTenCalls li a', function () {
 // code
});

这篇关于如何在jQuery列表视图中为特定链接创建点击事件。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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