Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/388.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
Javascript 简单if循环在jquery中不起作用_Javascript_Jquery_Forms_If Statement - Fatal编程技术网

Javascript 简单if循环在jquery中不起作用

Javascript 简单if循环在jquery中不起作用,javascript,jquery,forms,if-statement,Javascript,Jquery,Forms,If Statement,我的代码如下所示 <html> <form method="post"> <table class="table table-bordered"> <tr> <th colspan='3' style="text-align:center;">Enter Subject wise weightage </th> </tr&g

我的代码如下所示

   <html>
   <form method="post">
     <table class="table table-bordered">
        <tr>
          <th colspan='3' style="text-align:center;">Enter Subject wise weightage
          </th>
         </tr>
        <tr>
            <td colspan='2'><input type='hidden' name='Subject[]' value='ANATOMY' />ANATOMY
            </td>
            <td><input type='number' class='form-control individual' name='q_num[]' max=8 sub='ANATOMY'placeholder='Enter the number of Questions'/>     <p class='text-danger ANATOMY_error'></p>
            </td>
        </tr>
        <tr>
             <td colspan='2'><input type='hidden' name='Subject[]' value='BIOCHEMISTRY' />BIOCHEMISTRY
             </td>
             <td><input type='number' class='form-control individual' name='q_num[]' max=4 sub='BIOCHEMISTRY'placeholder='Enter the number of Questions'/><p class='text-danger BIOCHEMISTRY_error'></p>
             </td>
        </tr>
         <tr>
            <td colspan='2'><input type='hidden' name='Subject[]' value='PHYSIOLOGY' />PHYSIOLOGY
            </td>
            <td><input type='number' class='form-control individual' name='q_num[]' max=3 sub='PHYSIOLOGY'placeholder='Enter the number of Questions'/><p class='text-danger PHYSIOLOGY_error'></p>
            </td>
         </tr>
         <tr>
            <td colspan='2'><input type='hidden' name='Subject[]' value='ORTHOPEDICS' />ORTHOPEDICS
            </td>
             <td><input type='number' class='form-control individual' name='q_num[]' max=2 sub='ORTHOPEDICS'placeholder='Enter the number of Questions'/><p class='text-danger ORTHOPEDICS_error'></p>
            </td>
            </tr>   
        </table>    
       </form>

这以前对我有用,但现在我无法让它工作。模糊函数启动并正常工作,直到if循环启动。

这里的问题是,您的值是字符串,并且您将它们作为整数进行比较。因此,在进行比较时,您需要在途中转换它们:

if(parseInt(e) > parseInt(m)){
//and so on 
}

它的工作后,我修改了代码如下

jQuery(document).ready(function($){

     $('.individual').blur(function(){
        var m =parseInt($(this).attr("max"));
        var e = parseInt($(this).val());
        var s= $(this).attr("sub");
        var error = "."+ s +"_error";
     if(e>m){

             $(error).text("Please enter low value");
           }else{

            $(error).text('');
       }
     });

  });

谢谢..

请定义不工作。请注意,.attr和.val返回字符串,比较字符串可能会得到意想不到的结果。效果很好。非常感谢。现在它起作用了。
jQuery(document).ready(function($){

     $('.individual').blur(function(){
        var m =parseInt($(this).attr("max"));
        var e = parseInt($(this).val());
        var s= $(this).attr("sub");
        var error = "."+ s +"_error";
     if(e>m){

             $(error).text("Please enter low value");
           }else{

            $(error).text('');
       }
     });

  });