我需要重置一些只有唯一名稱(不是唯一的ID)的文本框。 我用jQuery試過,但我的代碼似乎什麼都不做:如何通過jQuery設置輸入元素的值,當我只知道它是「名稱」 - 屬性
$('input[name=customergroupname]').value="";
我需要重置一些只有唯一名稱(不是唯一的ID)的文本框。 我用jQuery試過,但我的代碼似乎什麼都不做:如何通過jQuery設置輸入元素的值,當我只知道它是「名稱」 - 屬性
$('input[name=customergroupname]').value="";
試試這個:
$('input[name="customergroupname"]').val("");
+1男子!現在我需要鍵入15個字符! –
獲取和設置包裹在一個jQuery對象表單元素的值正在與使用jQuery做val
功能:
$('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.
+1表示明確。 – thecodeparadox
傍晚傍晚+1 –
工作演示http://jsfiddle.net/vN74v/2/
代碼
$('#hullk').click(function(){ // in example when you click the button
$('input[name="customergroupname"]').val("");
});
據DOM level 2 specifications,您可以訪問:
document.forms["foo"].elements["customergroupname"].value = '';
如果formName
和fieldName
是常數,而不是變量,你CA n使用文本語法:
document.forms.foo.elements.customergroupname.value = '';
'$( '輸入[名稱= customergroupname]')VAL( 「」);' – rubish
@rubish:把它作爲一個答案 – zerkms
@rubish:把它作爲一個答案 –