我有一个表单,第一个 .class 有 5 个输入:文本框。我希望能够通过单击按钮来清除所有文本框。我尝试了几种方法,但不起作用...这就是我所做的...(仅供引用,我的表单中有更多类,所以我无法使用 .reset。
表格...
<table class="orderLine1 formFont" width="900">
<tr>
<td width="395">Product Name:<br><input class="ProductName" type="text" size="65"></td>
<td width="97" class="formFontDisabled">Prod ID:<br><input class="Product_ID ffd" type="text" size="5" disabled></td>
<td width="78" class="formFontDisabled">UPC:<br><input class="UPC ffd" type="text" size="13" disabled ></td>
<td width="67" class="formFontDisabled">List Price:<br><input class="ListPrice ffd" type="text" size="7" disabled></td>
<td width="67">WholeSale:<br><input class="WholeSalePrice ffd" type="text" size="7" disabled></td>
<td width="56">Quantity:<br><input class="qty addLine" type="text" size="7"></td>
<td width="60" class="formFontDisabled">Line Total:<br><input class="subTotal ffd" type="text" size="10" disabled></td>
<td width="44"><button class="OFDeleteButton">Delete</button><button class="OFClearLine" >OFClearLine</button></td>
</tr>
</table>
脚本测试#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('');
});
});
关于JQuery如何清除表单上所有输入:textfields of a .类。不为我工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8054377/