如何使用jquery验证文本框控件?

编程入门 行业动态 更新时间:2024-10-25 20:26:55
本文介绍了如何使用jquery验证文本框控件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何在表单子目录之前在表单中逐个检查文本框是否为空。使用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验证文本框控件?

本文发布于:2023-11-11 23:46:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1579880.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   控件   文本框   jquery

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!