0

有人可以让我朝着这个代码片段的正确方向前进吗?

function validateForm() {
    var flag=1;
//i have array containg values some values array[]
    $(document).ready(function () {
      alert("what happened");
      //my form contains dynamically generated input fields..
     //i can't seem to generate the ids.. 
    var y=$("#inputfield"+array[1]).val();// seems to me like error in this line
    //{validation code using y}
    flag = 0;
});
if (flag === 0) {

    return false;
}

}

这是html部分:

<form action="L4.php" method="post" onSubmit="return validateForm();">
<input type="submit">
</form>
4

2 回答 2

0

尝试这个,

function validateForm() {
    var flag=1;
    $('form input[type="text"]').each(function(){//looping for all textboxes
        if($(this).val()=="")//if the textbox is empty
            flag=0;
    });
    if (flag === 0) {
        alert('error');
        return false;
    }
    return true;// if ok then return true
}
于 2013-07-23T06:54:32.730 回答
0
  var input= $('input').filter(function(){ return this.id.match("input_type");});

    $.each(input, function(i,obj){
            var id = "#"+$(input[i]).attr('id');
                    if(id.match(/Fname/)){
                          //do something
                    }else if(id.match(/Lname/)){
                         //do something  
                    }
        });
于 2013-07-23T06:19:06.770 回答