JQuery如何清除所有输入:表单上.class的文本字段。 不适合我

我有一个表单,第一个.class有5个输入:文本框。 我希望能够通过单击按钮清除所有文本框。 我已经尝试了几种方法而且它不起作用……这就是我所做的……(仅供参考,我在表单中有更多的类,所以我不能使用.reset。

表格…

Product Name:
Prod ID:
UPC:
List Price:
WholeSale:
Quantity:
Line Total:

脚本测试#1

  $(document).ready(function(e) { $(function clearFirst() { $('.orderLine1').find(':input').each(function() { switch(this.type) { case 'text': $(this).val(''); break; } }); }); $('.OFClearLine').click(function(e) { clearFirst(); }); }); 

脚本测试#2

  $(function(){ $('.OFClearLine').bind('click', function(){ $('.orderLine1').reset(); }); }); 

更多信息:OFClearLine是我想要使用的按钮的类,orderLine1是表单的类。

提前致谢!

 $(function() { $('.OFClearLine').click(function() { $('.orderLine1 input[type="text"]').val(''); }); }); 

像这样的东西应该工作:

 $("input.className:text").val(""); 

查看您的代码,这可能会更好:

 $(".className input[type='text']").val(""); 

这是一个jsFiddle: http : //jsfiddle.net/nvUsD/1/

以下代码将查找作为.orderLine1表元素的.orderLine1所有文本输入,并将其值设置为.orderLine1

 $('.OFClearLine').bind('click', function(){ $('.orderLine1').find('input[type="text"]').val(''); }); 

试试这个:

 $(document).ready(function(e) { $('.OFClearLine').click(function(e) { $('.orderLine1 input:text').each(function() { $(this).val(''); }); }); }); 

你可以在这个小提琴上看到它, http://jsfiddle.net/nickyt/exWKL

我不确定它是否能看到你的clearFirstfunction。 您也可以使用$(’。orderLine1 input’)查找.orderLine1类中的所有输入。

 $(document).ready(function(e) { $('.OFClearLine').click(function(e) { clearFirst(); }); }); function clearFirst() { $('.orderLine1 input[type="text"]').each(function() { $(this).val(''); }); }