jQuery 清除输入[类型=密码]
当 jquery 验证失败时,我试图清除所有密码类型的输入 - 我尝试了以下操作(不起作用):
$('input[type=password]').val('');
有什么想法吗?
I'm trying to clear all the inputs that are password type when jquery validation fails - I tried the following (which doesn't work) :
$('input[type=password]').val('');
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
尝试用
Try with
尝试使用
:password
选择器,因为它会使您的代码更短:也是您的初始代码应该有效。你的问题出在别的地方。不幸的是,由于您没有说明在什么上下文中以及如何调用它,或者因为您没有解释它不起作用意味着我无法进一步帮助您。
Try using the
:password
selector as it will make your code shorter:Also your initial code should work. Your problem is somewhere else. Unfortunately as you haven't stated in what context and how this is called or as you haven't explained what it doesn't work mean I cannot help you further.
简短回答:
要使用 jquery 选择所有密码字段,您可以使用:
但为了在现代浏览器中获得更好的性能,请使用
详细答案
:密码选择器 (来自 jQuery 文档)
描述:选择密码类型的所有元素。
添加版本:1.0
jQuery( ":password" )
$( ":password" ) 相当于 $( "[type=password]" )。
与其他伪类选择器(以“:”开头的选择器)一样,建议在其前面添加标签名称或其他选择器;否则,隐含通用选择器(“*”)。
换句话说,裸露的 $( ":password" ) 相当于 $( "*:password" ),因此应该使用 $( "input:password" ) 来代替。
附加说明:
因为 :password 是 jQuery 扩展,而不是 CSS 规范的一部分,所以使用 :password 的查询无法利用本机 DOM querySelectorAll() 方法提供的性能提升。为了在现代浏览器中获得更好的性能,请改用 [type="password"]。
short answer :
to select all password fields using jquery you can use :
but for better performance in modern browsers use
Detailed Answer
:password Selector ( from jQuery document )
Description: Selects all elements of type password.
version added: 1.0
jQuery( ":password" )
$( ":password" ) is equivalent to $( "[type=password]" ).
As with other pseudo-class selectors (those that begin with a ":") it is recommended to precede it with a tag name or some other selector; otherwise, the universal selector ( "*" ) is implied.
In other words, the bare $( ":password" ) is equivalent to $( "*:password" ), so $( "input:password" ) should be used instead.
Additional Notes:
Because :password is a jQuery extension and not part of the CSS specification, queries using :password cannot take advantage of the performance boost provided by the native DOM querySelectorAll() method. For better performance in modern browsers, use [type="password"] instead.
我想你可以尝试这个:
I think you can try this: