简体   繁体   English

如何显示隐藏的输入字段

[英]How can i show hidden input fields

I have a question.我有个问题。

When I have form with lets say about 100 hidden input fields, how can I show them one by one after I press enter in the last shown input field?当我有大约 100 个隐藏输入字段的表单时,如何在最后显示的输入字段中按 Enter 后一一显示它们?

This adds a key handler to each type="text" field.这会为每个type="text"字段添加一个键处理程序。 The key handler tests whether the field is the last type="text" field, and if the key was the Enter key.键处理程序测试该字段是否是最后一个type="text"字段,以及该键是否是 Enter 键。 If so, it finds the next type="hidden" field, sets its type to "text", and adds the handler to it.如果是这样,它会找到下一个type="hidden"字段,将其类型设置为“text”,并将处理程序添加到其中。

 function callback(e){ if ( // If it's the last text field $(this).index() == $('#demo input[type="text"]').length - 1 && // And the key pressed is Enter: e.which == 13 ) { // Find next hidden field, change it to text, and add the key handler: $(this).next('input[type="hidden"]').prop("type", "text").keypress(callback) } } // Add key handler to all text fields: $('#demo input[type="text"]').keypress(callback)
 <script src="https://code.jquery.com/jquery-3.6.0.js" integrity="sha256-H+K7U5CnXl1h5ywQfKtSj8PCmoN9aaq30gDh27Xc0jk=" crossorigin="anonymous"></script> <div id="demo"> <input type="text"> <input type="text"> <input type="text"> <input type="hidden" value="hidden1"> <input type="hidden" value="hidden2"> <input type="hidden" value="hidden3"> </div>

References:参考:

jQuery: how do I check if an element is the last sibling? jQuery:如何检查一个元素是否是最后一个兄弟?

How can I detect pressing Enter on the keyboard using jQuery? 如何使用 jQuery 检测键盘上的 Enter 键?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在用Mechanize隐藏的输入上设置字段? - How can I set fields on an input hidden with Mechanize ? 如果定义了隐藏输入字段的值,该如何显示? - How can I show the value of a hidden input field if the value is defined? 如何显示jquery中的隐藏内容? - how can i show the hidden content in jquery? 如何使用javascript更新隐藏输入字段的值 - How do I use javascript to update the values of hidden input fields 如果以前的输入具有有效值,我该如何显示输入字段? - How can I show input fields only when previous input has a valid value? 如何将第1页的输入字段传递给第2页的隐藏字段,然后在javascript中显示第2页到第3页的隐藏字段? - How do I pass input fields from page 1 to hidden fields on page 2 and then display hidden fields from page 2 to page 3 in javascript? 如何首先隐藏输入字段,它首先是 label 然后它会在我单击按钮时显示 - How can I hide first the input fields and it's label first then it will show when I clicked the button Gravity Forms正在验证隐藏字段,如何解决此问题? - Gravity Forms is validating hidden fields, how can I fix this? 如何添加 JS function 以使包括输入字段在内的所有数字显示千分隔符? - How can I add a JS function to make all numbers including INPUT fields show the THOUSAND SEPARATOR? 如何从用户输入字段中获取数据并在不提交的情况下向用户显示? - How can I get the data from user input fields and show user back without submission?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM