如何在表单子目录之前在表单中逐个检查文本框是否为空。使用jquery? 我尝试了什么: i尝试了但是只有一个,如果条件仅在填写最后一个文本框后才工作,那么其他块正在工作吗? <!DOCTYPE html> < html> < head> < script src =ajax.googleapis/ajax/libs/jquery/1.11.2/jquery.min.js> < / script> < script> $(document).ready(function(){ $(#btnSubmit)。click(function(){ if($(#txtone)。val()==) { $('#my')。html('0ne enter'); //将文字附加到所有p元素 } if($(#txt2)。val()==) { $('#my')。html('2 enter'); //将文字附加到所有p元素 } if($(#txt3)。val()==) { $('#my') .html('3 enter'); //将文字附加到所有p元素 } else {alert(ok);} } ); $('div') .append('这是div。'); //将文字附加到所有div元素 }); < / script> <风格> div { 边框:1px实体; } p { border:1px dashed; } < / style> < / head> < body>
How to check textboxs are empty or not one by one in a form before form submition. using jquery? What I have tried: i have tried but only one that last if condition is only working after filling the last textbox next else block is working? <!DOCTYPE html> <html> <head> <script src="ajax.googleapis/ajax/libs/jquery/1.11.2/jquery.min.js"> </script> <script> $(document).ready(function () { $("#btnSubmit").click(function(){ if($("#txtone").val() == "") { $('#my').html('0ne enter'); // appends text to all p elements } if($("#txt2").val() == "") { $('#my').html('2 enter'); // appends text to all p elements } if($("#txt3").val() == "") { $('#my').html('3 enter'); // appends text to all p elements } else{alert("ok");} } ); $('div').append('This is div.'); // appends text to all div elements }); </script> <style> div{ border: 1px solid; } p{ border: 1px dashed; } </style> </head> <body>
< input type =textid =txtone/> < input type =textid =txt2/> < input type =textid =txt3/> < input type =buttonid =btnSubmit/> <input type="text" id="txtone"/> <input type="text" id="txt2"/> <input type="text" id="txt3"/> <input type="button" id="btnSubmit"/>
< / body> < / html>
</body> </html>
推荐答案(document).ready(function(){ (document).ready(function () {
(#btnSubmit)。click(function(){ if( ("#btnSubmit").click(function(){ if(
(#txtone)。val()==) { ("#txtone").val() == "") {
更多推荐
如何使用jquery验证文本框控件?
发布评论