我需要重置一些只有唯一名称(不是唯一 ID)的文本框。我用 jQuery 尝试过,但我的代码似乎什么也没做:
$('input[name=customergroupname]').value="";
我需要重置一些只有唯一名称(不是唯一 ID)的文本框。我用 jQuery 尝试过,但我的代码似乎什么也没做:
$('input[name=customergroupname]').value="";
试试这个:
$('input[name="customergroupname"]').val("");
使用 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.
工作演示 http://jsfiddle.net/vN74v/2/
代码
$('#hullk').click(function(){ // in example when you click the button
$('input[name="customergroupname"]').val("");
});
根据DOM 2 级规范,您可以访问:
document.forms["foo"].elements["customergroupname"].value = '';
如果formName
andfieldName
是常量而不是变量,则可以使用文字语法:
document.forms.foo.elements.customergroupname.value = '';
尝试:
$('input[name="customergroupname"]').value="";
我已经用customergroupname
引号括起来了。
非常真实,我把引号弄混了。现已编辑。