Using jQuery mobile button to run javascript

安稳与你 提交于 2019-12-13 07:19:54

问题


Using a script that reference jQuery Mobile I have the following line:

<a href="#" id="buttonAnswer1" data-role="button" data-inline="true" >check</a>

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>

回答1:


This isn't really any different then regular jQuery, that is you can use .on to bind an event handler

For example, using .on with event delegation

$(document).on('click', '#buttonAnwser1', hello);

Or you can bind it directly

$('#buttonAnswer1').on('click', hello);


来源:https://stackoverflow.com/questions/13794480/using-jquery-mobile-button-to-run-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!