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;
.
精彩评论