[英]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.