开发者

java script for button click recognition

开发者 https://www.devze.com 2023-01-03 23:18 出处:网络
How can i check whether a button is clicked or not using 开发者_运维百科javascriptIf you are talking about a <button>, use the onclick event.

How can i check whether a button is clicked or not using 开发者_运维百科javascript


If you are talking about a <button>, use the onclick event. The dirty way to do so would be <button onclick="your javascript here">...</button>.

The clean way is registering an event handler from your javascript code. e.g. if you are using jQuery in this way:

$('#id-of-your-button').click(function(e) {
    e.preventDefault();
    /* do something */
});`

The preventDefault() call ensures no side-effects like submitting a form occur. When using the dirty inline way, you can achieve that by ending the code with return false;.

0

精彩评论

暂无评论...
验证码 换一张
取 消