empty field validation in jquery

前端 未结 2 635
迷失自我
迷失自我 2021-01-25 22:02

I have 3 text fields.

The first field is the only mandatory field, but if the second field is not empty the first and third text field should not be empty.

How

2条回答
  •  青春惊慌失措
    2021-01-25 22:22

    Simple:

    var set = $('input[type="text"]');
    if(set.eq(0).val().length == 0 || (set.eq(1).val().length > 0 && set.eq(2).val().length == 0)) {
       //throw error
    } 
    

提交回复
热议问题