将按钮重置为输入框的默认值 [英] Reset button to default value for input box
本文介绍了将按钮重置为输入框的默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个输入框,访客可以在其中更改值
I have an inputbox where visitors can change the value
<input id="custom_coverage" type="text" value="320" name="custom_coverage">
当他们更改值时,它将通过另一个jQuery脚本进行计算.
When they change the value, it makes a calculation on the by another jQuery-script.
如何在输入框旁边添加按钮或链接,以便访问者可以将其恢复为默认值?
How can i add a button or a link next to the input box, so visitors can put it back to the default value?
推荐答案
将原始值存储在data
属性中,例如<input id="custom_coverage" type="text" value="320" data-original-value="320" name="custom_coverage">
Store the original value in a data
attribute, e.g. <input id="custom_coverage" type="text" value="320" data-original-value="320" name="custom_coverage">
并添加一个可再次切换值的按钮:
And add a button that switches the values again:
<a href="#" class="restore">Restore</a>
<script>
$(document).on("click", ".restore", function(){
var custom_coverage = $("input#custom_coverage");
custom_coverage.val(custom_coverage.data("original-value"));
});
</script>
示例: http://jsfiddle.net/deDdy/
这篇关于将按钮重置为输入框的默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文