本文介绍了jQuery的按钮点击不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用jQuery Mobile的点击功能,但是,它不工作。
I am using jquery mobile click function, however, it is not working.
下面是我有按钮的一个例子,它包含一个网格内
Here is an example of the button that I have, and it is contained within a grid:
<div class="ui-block-c"><a class="request" data-role="button" data-id="\"'+json[i].num+'\" data-type="3" data-icon="plus" data-iconpos="right">Test</a></div>
jQuery函数:
jQuery function:
$('.request').on('click', function() {
alert("hi");
});
我该如何解决这个问题?
How do I fix this?
推荐答案
看起来你是动态添加这个元素,所以你需要使用委派事件侦听器:
It looks like you are adding this element dynamically, so you'll need to use a delegated event listener:
$(document).on('click', '.request', function() {
alert("hi");
});
你也有你的转义引号不匹配的问题。我不认为这是必要的:
Also you have an issue with your escaped quotes not matching. I don't think those are necessary:
<div class="ui-block-c"><a class="request" data-role="button" data-id="'+json[i].num+'" data-type="3" data-icon="plus" data-iconpos="right">Test</a></div>
这篇关于jQuery的按钮点击不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!