簡體   English   中英

設置重置按鈕以清除文本類型的特定單個輸入

[英]Set a reset button to clear a specific single input of type text

我有以下幾點:

<div id="section1">
 <label> Label 1 </label>
 <br>
 <input type="text" id="input_section1">
 <button type="reset" class="clear"></button>
</div>

這就是 html 必須保持結構化的方式。 我在頁面上還有其他與上述相同的 div(稱為#section2、#section3 等),並且沒有任何輸入位於表單內。

所以我想要的是重置與其關聯的特定輸入的按鈕; 在上述情況下,輸入“#input_section1”。

當我單擊重置按鈕時,它正在清除頁面上的每個輸入。

一個簡單的解決方案:

<input type="button" onClick="document.getElementById('input_secion1').value='';">

這應該做你所要求的。

您可以使用.siblings()使用以下 jquery 代碼:

$(document).on('click','.clear',function(){
    $(this).siblings( "input" ).val('');
});

這將找到當前單擊元素的input type sibling並將其重置。

小提琴

暫無
暫無

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

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