开发者

java script for button click recognition

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜