簡體   English   中英

如何顯示隱藏的輸入字段

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

參考:

jQuery:如何檢查一個元素是否是最后一個兄弟?

如何使用 jQuery 檢測鍵盤上的 Enter 鍵?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM