-1

i have a button and some inputs, i want to let jquery check for me if none of the inputs is empty before doing some action : so this is what i've done :

$('#my_button)').click(function() {
if(
for(i=0;i<$('#my _button').parent().prev().children().children().length;i++){){ //this is to check if the inputs exist
$('#my_button').parent().prev().children().children().eq(i).val()!==''; // i've tried .val().is(:empty); but not working too
//so the test fails for somehow ! and the if condition doesn't work
// google chrome developers inspector gives me this error (Uncaught SyntaxError: Unexpected token for)
}
){
//do some action
}}

and this is my jsfiddl test !

4

2 に答える 2

0

予期しないトークンでforあるため、予期しないトークンの警告が表示されます。if ステートメントのブール式にループを入れることはできません。for

次の疑似コードと同様のことを行う必要があります。

$('#my_button').click(function() {
  succeed = true;
  for all of my inputs {
    if(input is empty){
       succeed = false;
    }
  }
  if(succeed) //do stuff
}
于 2013-01-15T15:43:19.397 に答える
0
<table>
 <tr>
  <td>
   <div><input id='i1'></div>
   <div><input id='i2'></div>  
  </td>
  <td><button id='my_button'>click me</button></td>
 </tr>
</table>

脚本:

    $('#my_button').on('click', function() {
        var in1 = $('#i1').val();
        var in2 = $('#i2').val();

        if(in1 != '' && in2 != ''){
               // do something
            }
            else{
              //alert

            }
    }
于 2013-01-15T15:40:53.240 に答える