[英]Set a reset button to clear a specific single input of type text
I have the following:我有以下几点:
<div id="section1">
<label> Label 1 </label>
<br>
<input type="text" id="input_section1">
<button type="reset" class="clear"></button>
</div>
This is how the html must remain structured.这就是 html 必须保持结构化的方式。 I have other divs on the page that are the same as the above (called #section2, #section3 etc), and none of the inputs are within a form.
我在页面上还有其他与上述相同的 div(称为#section2、#section3 等),并且没有任何输入位于表单内。
So what I want is the button to reset the specific input it is associated with;所以我想要的是重置与其关联的特定输入的按钮; in the case above, the input '#input_section1'.
在上述情况下,输入“#input_section1”。
At the moment when I click the reset button it is clearing every input on the page.当我单击重置按钮时,它正在清除页面上的每个输入。
a simple solution:一个简单的解决方案:
<input type="button" onClick="document.getElementById('input_secion1').value='';">
This should do what you are asking for.这应该做你所要求的。
You can use the following jquery code using .siblings()
:您可以使用
.siblings()
使用以下 jquery 代码:
$(document).on('click','.clear',function(){
$(this).siblings( "input" ).val('');
});
This will find the input type sibling
of the current clicked element and reset it.这将找到当前单击元素的
input type sibling
并将其重置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.