1

我需要重置一些只有唯一名称(不是唯一 ID)的文本框。我用 jQuery 尝试过,但我的代码似乎什么也没做:

$('input[name=customergroupname]').value="";
4

5 回答 5

4

试试这个:

$('input[name="customergroupname"]').val("");
于 2012-05-28T09:03:53.420 回答
3

使用 jQueryval函数获取和设置包裹在 jQuery 对象中的表单元素的值:

$('input[name="customergroupname"]').val("");

.value只能用于 DOM 元素,如下所示:

$('input[name="customergroupname"]').eq(0).value ="";

$(...)       // This is a jQuery object.
$(...)[n]    // This is a DOM object in the nth place in the set.
$(...).eq(n) // This is a DOM object in the nth place in the set.
于 2012-05-28T09:04:27.337 回答
0

工作演示 http://jsfiddle.net/vN74v/2/

代码

$('#hullk').click(function(){ // in example when you click the button
    $('input[name="customergroupname"]').val("");
});
​
于 2012-05-28T09:08:29.830 回答
0

根据DOM 2 级规范,您可以访问:

document.forms["foo"].elements["customergroupname"].value = '';

如果formNameandfieldName是常量而不是变量,则可以使用文字语法:

document.forms.foo.elements.customergroupname.value = '';
于 2012-05-28T09:15:20.187 回答
-3

尝试:

$('input[name="customergroupname"]').value="";

我已经用customergroupname引号括起来了。

非常真实,我把引号弄混了。现已编辑。

于 2012-05-28T09:05:22.043 回答