How do I invoke button click function in Jquery
I have got the following code in html
<div class="functionitem" id开发者_如何学运维="viewresult"><span class="button"><span>
<input type="button" class="form_button" value=" View"></span></span>
</div>
So I try to using the following jquery click function to invoke a method when the button get clicked, this is what I have done
$("#viewresult:button").click(function () {
//methods
});
But it's not working, what did I do wrong, please help, thanks
Your selector is wrong. It is trying to find a button with id viewresult
. Putting a space between the two will indicate that the button should be a descendant of the viewresult
element.
$("#viewresult :button").click(function () {
//methods
});
Leave a space in your selector. :button
is a descendant of #viewitem
, not a qualifying property. e.g.
$('#viewitem :button').click(...);
That says "a :button that falls under the #viewitem element"
$("#viewresult input:button").click(function () {
//methods
});
精彩评论