The situation is as follows: I have a form that needs to dynamically add input items, and the name of each input item is the same. Since non-null verification is required, consider using jquery to obtain the value of each element and judge it.
code show as below:
$("#reg").click(function(){
for(var i=0;i <= reNum - 1;i++){ alert(i); alert($("input[name='userLoginNo']:eq(i)").val()); } })
Among them, reg is the submit button (type is button), which will be verified after clicking. If all are not empty, submit. But when I want to capture the value of each input, I can only spit out undefined.
If you change the i in alert($("input[name='userLoginNo']:eq(i)").val()); to a direct number, such as alert($("input[name= 'userLoginNo']:eq(0)").val()); can display the input value normally
Please help us find out why, thank you very much~
The variables in your eq are strings, not variables. You need to use "+i+"
The variable i should be used as a dynamically changing parameter instead of being placed in double quotes as a fixed string i. Change it to this and you can read: $("input[name='userLoginNo']:eq("+i+")").val(). Tested myself.