使用jQuery移动按钮运行javascript [英] Using jQuery mobile button to run javascript
本文介绍了使用jQuery移动按钮运行javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用引用jQuery Mobile的脚本,我有以下内容:
Using a script that reference jQuery Mobile I have the following line:
<a href="#" id="buttonAnswer1" data-role="button" data-inline="true" >check</a>
当单击此按钮并说调用hello()函数时,如何添加侦听器?即
How would I add a listener for when this button is clicked and lets say call the hello() function? i.e.
<a href="#" id="buttonAnswer1" data-role="button" data-inline="true">check</a>
<script>
function hello(){
console.log("hello world");
}
</script>
推荐答案
This isn't really any different then regular jQuery, that is you can use .on to bind an event handler
例如,将.on与事件委托配合使用
For example, using .on with event delegation
$(document).on('click', '#buttonAnwser1', hello);
或者您可以直接将其绑定
Or you can bind it directly
$('#buttonAnswer1').on('click', hello);
这篇关于使用jQuery移动按钮运行javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文