开发者

How do I invoke button click function in Jquery

开发者 https://www.devze.com 2023-04-04 13:50 出处:网络
I have got the following code in html <div class=\"functionitem\" id开发者_如何学运维=\"viewresult\"><span class=\"button\"><span>

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
 });
0

精彩评论

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