how do i find out if a certain button has been clicked like in check boxes
e.g
if()// button1 is clicked
{
alert("Button 1 was clicked");
}
if()// button2 开发者_开发问答is clicked
{
alert("Button 2 was clicked");
}
//you can change type to submit if its a form submit button
$("input[type='button']").click(function(){
alert("button with the id: "+$(this).attr("id")+" was clicked!");
});
You can use the button id as an identifier.
jQuery('#button1, #button2').click(function () {
if (this.id == 'button1') {
alert('Button 1 was clicked');
}
else if (this.id == 'button2') {
alert('Button 2 was clicked');
}
});
I'm assuming in my answer that you are looking for whether a checkbox has been checked, and not clicked. That would seem the most logical inference from your question. Let me know if this is incorrect.
Use the .is() function
if ($("#Button1").is(":checked")){
alert("Button 1 was clicked");
}
if ($("#Button2").is(":checked")){
alert("Button 2 was clicked");
}
$('#button1').click(function() {
alert('Button 1 Clicked');
}
$(":button").click(function(){
var $id=$(this).attr("id");
alert("Button"+ id);
});
it will work for each button type input element
精彩评论