[英]How can i show hidden input fields
我有个问题。
当我有大约 100 个隐藏输入字段的表单时,如何在最后显示的输入字段中按 Enter 后一一显示它们?
这会为每个type="text"
字段添加一个键处理程序。 键处理程序测试该字段是否是最后一个type="text"
字段,以及该键是否是 Enter 键。 如果是这样,它会找到下一个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>
参考:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.