Javascript 如何仅在以前的输入具有有效值时显示输入字段?
我有一个表单,需要3到10个文本输入项。当窗体首次加载时,它将显示3个输入(最少) 我希望高效地显示输入行,因为前一行具有有效值(例如,假设大于3个字符)。因此,如果您填写前3行,您将自动看到第4个可选输入行 你能帮我在jQuery中高效地循环这个快速列表吗 HTML:Javascript 如何仅在以前的输入具有有效值时显示输入字段?,javascript,jquery,forms,loops,Javascript,Jquery,Forms,Loops,我有一个表单,需要3到10个文本输入项。当窗体首次加载时,它将显示3个输入(最少) 我希望高效地显示输入行,因为前一行具有有效值(例如,假设大于3个字符)。因此,如果您填写前3行,您将自动看到第4个可选输入行 你能帮我在jQuery中高效地循环这个快速列表吗 HTML: 这非常简单——如果让jQuery的链接来完成工作,您甚至不需要循环。我会这样做: $("#myform input").change(function(){ //If an input in your form is chang
这非常简单——如果让jQuery的链接来完成工作,您甚至不需要循环。我会这样做:
$("#myform input").change(function(){ //If an input in your form is changed,
if ($(this).val() == 42){ //replace with your validation logic :)
$(this).next('input').show(); //This shows the next sibling element to the triggering element
} else { //but if it fails validation...
$(this).nextAll('input').hide().val(""); //hide them and delete the contents to stop the form from uploading invalidated data!
}
});
这就是你所要求的,对于奖励积分,如果他们的前辈后来被更改为无效,它会隐藏并清空后面的框。如果这些是唯一标识符,那么
class=“item\u X”
应该是一个id:id=“item\u X”
——另外,如果你达到了,比如说,item\u 7,你希望发生什么(1-6有效,因此显示7)然后返回并更改项目_3,使其不再有效?
.item_4,.item_5,.item_6,.item_7,.item_8,.item_9,.item_10 { display:none }
$("#myform input").change(function(){ //If an input in your form is changed,
if ($(this).val() == 42){ //replace with your validation logic :)
$(this).next('input').show(); //This shows the next sibling element to the triggering element
} else { //but if it fails validation...
$(this).nextAll('input').hide().val(""); //hide them and delete the contents to stop the form from uploading invalidated data!
}
});