I just came into contact with jQuery today
$("#Button1").click( function() { alert('我被点了') });
There is no response after clicking Button1, please help to modify it
The final desired effect is that after clicking Button1, Determine whether the value of textbox1 is empty. If it is empty, pop up "alert('textbox1 cannot be empty')"
$(document).ready(function(){ $("#Button1").bind("click", function() { if($.trim($("#textbox1").val())=="") {alert('我被点了');} }); });
It should be noted that # is just a modifier, not the person part of the ID
<button id="Button1">Button1</button>
<button id="Button1">Button1</button> $("#Button1").click(function(){ if( $('.textbox1').val() == "" ){ alert('textbox1不能为空'); } })
Maybe you didn’t add
$(document).ready(function(){ });
...
Maybe it’s the control# of your Button1 ID ##has not been loaded yet. Just load it out or you can put the JS code for execution later instead of in the
Head part, which is also good for SEO.
$(function(){ $('#Button1').click(function(){ $('#textbox1').val()==''?alert('textbox1不能为空'):alert('我被点击了'); }); })
The above is the detailed content of Detailed explanation of how to use Button's click event in jQuery. For more information, please follow other related articles on the PHP Chinese website!