Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 使用jquery检查文本框的验证_Php_Jquery - Fatal编程技术网

Php 使用jquery检查文本框的验证

Php 使用jquery检查文本框的验证,php,jquery,Php,Jquery,我有一些文本框,它们的值是从某个源生成的。因此在编辑它们时,如果我删除这些值,然后单击“提交”按钮,我的jquery验证将不起作用 我正在使用这个jquery $(function() {$("#error1").hide();}); $('#save').click(function() {             $('input:text').each(function(){       if( $(this).val().length == 0)          $("#

我有一些文本框,它们的值是从某个源生成的。因此在编辑它们时,如果我删除这些值,然后单击“提交”按钮,我的jquery验证将不起作用 我正在使用这个jquery

$(function() {$("#error1").hide();});

$('#save').click(function() { 
         
     $('input:text').each(function(){
       if( $(this).val().length == 0)
          $("#error1").show('slow');
  
    });
});
通过这个jquery,我想验证我的所有文本框。甚至我所需的字段验证器也不起作用。这可能是一个老问题,但我试图找到解决方案,但没有得到任何有效的答案。请帮助。

试试这个

$(function() {
    $("#error1").hide();
    $('#save').click(function() { // write this in document.ready function
        var flag=false;
        $('input:text').each(function(){
           if( $(this).val().length == 0) {
              flag=true;
              return false; //break the loop if showing common message
           }
        });
        if(flag === true) {// show error once only
             $("#error1").show('slow');
        }
    });
});
检查这个 JQuery HTML

文本框不能为空


您可以试试这个JSFIDLE

脚本

$(function() {$("#error1").hide();});

$('#save').click(function() {
     validInput = true;
     $('input:text').each(function(){
         if($(this).val().length === 0) {
            validInput = false;
            $(this).addClass("input-error");
            $("#error1").show('slow');
         }
    });
    if(validInput) {
        $("#myForm").submit();
    }
});

你可以试试html5模式吗?谢谢你的帮助,但这还是绕过了验证。我还提供了一个警告框,看看代码是否正常工作,当然代码正常工作,但验证不正常。你能像在小提琴上一样为它做一个在线演示吗?
<input type="text" id="txtname" name="txtname">
<input type="submit" id="save" />
<p id="error1">Textbox can not be blank.!</p>
$(function() {$("#error1").hide();});

$('#save').click(function() {
     validInput = true;
     $('input:text').each(function(){
         if($(this).val().length === 0) {
            validInput = false;
            $(this).addClass("input-error");
            $("#error1").show('slow');
         }
    });
    if(validInput) {
        $("#myForm").submit();
    }
});