jQuery的:如何使一个明确的按钮? [英] jQuery: How to make a clear button?
问题描述
我有一个搜索栏,我需要一个明确的按钮。
I have a search field, and I need a clear button.
我目前拥有的按钮,但我不知道怎么办呢,
I currently have the button, but I don't know how to do it,
我有6个文本框,2组合框和2多重选择列表
I have 6 textfields, 2 comboboxes, and 2 multiple select lists
如何清除所有的人都在一个清晰的功能?
我知道HTML的方式,但我使用Grails和类型=重置是行不通的。
这就是为什么我要删除文本框的价值观,使组合框的第一个索引的一个jQuery的方式,并从多个选择列表中清除所有选项。
How do I clear all of them in one clear function?? I know the HTML way, but I am using Grails and the type="reset" does not work. That's why I want a jQuery way of deleting textboxes' values, leaving the combobox in the first index, and clear all options from the multiple select list.
感谢您的帮助:D
推荐答案
您可以修改下面的code,以满足您的需求。这是一个从这个线程反正。
You can modify the code below to suit your needs. It's stolen from this thread anyway.
$(':input','#myform')
.not(':button, :submit, :reset, :hidden')
.val('')
.removeAttr('checked')
.removeAttr('selected');
<form id='myform'>
<input type='text' value='test' />
<select id='single'>
<option>One</option>
<option selected="true">Two</option>
</select>
<select multiple="true" size="5" id='multiple'>
<option>One</option>
<option selected="true">Two</option>
</select>
<input type='button' id='reset' value='reset' />
</form>
的编辑(要清除多个选择):的
$('#reset').click(function(){
$(':input','#myform')
.not(':button, :submit, :reset, :hidden')
.val('')
.removeAttr('checked')
.removeAttr('selected');
$("#myform #multiple").empty();
});
这篇关于jQuery的:如何使一个明确的按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!