在Jquery中选择所有空文本字段 [英] Selecting all empty text fields in Jquery

查看:78
本文介绍了在Jquery中选择所有空文本字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何查找所有具有空值的文本字段?

How can I find all text fields that have an empty value?

$(":text[value='']")  

出现JavaScript错误

gives a JavaScript error

我知道我可以做$(":text"),遍历并用$(this).val()==''返回所有字段

I know I can do $(":text"), iterate through and return all fields with $(this).val()==''

我正在寻找一种更清洁的方法并使用JQuery 1.3.1 如果元素在页面加载时最初具有值,然后用户清除了它,则它必须起作用. ($("#elem").attr('value')给出了该位置的原始值,尽管.val()正常工作)

I am looking for a cleaner method and using JQuery 1.3.1 It has to work if the element originally had a value when the page was loaded, and then the user cleared it. ($("#elem").attr('value') gives the original value in that place, though .val() works properly)

推荐答案

最新答案:升级到1.3.2

以下是我通过FireBug在 http://docs.jquery.com/Downloading_jQuery 上运行的各种测试

Latest Answer: Upgrade to 1.3.2

Here are various tests I ran via FireBug on http://docs.jquery.com/Downloading_jQuery

不同的jQuery版本在页面加载时使用特殊的lublessmonkey脚本进行了切换.

Different jQuery versions are switched in at page-load with special greasemonkey scripts.

>>> jQuery.prototype.jquery
"1.3.2"
>>> jQuery(":text[value='']")
[input#jq-primarySearch]
Unknown pseudo-class or pseudo-element 'text'.
>>> jQuery(":text[value=]").get()
[input#jq-primarySearch]

>>> jQuery.prototype.jquery
"1.3.1"
>>> jQuery(":text[value='']")
Syntax error, unrecognized expression: value='']
>>> jQuery(":text[value=]").get()
[input#jq-primarySearch]

>>> jQuery.prototype.jquery
"1.3"
>>> jQuery(":text[value='']");
Object length=1 prevObject=Object context=document
Unknown pseudo-class or pseudo-element 'text'.
[Break on this error] undefined
>>> jQuery(":text[value=]").get()
[input#jq-primarySearch]

请注意,1.3和1.3.2可以正确处理它(尽管Firefox发送错误),但是它们仍然可以正确处理节点.

Note that 1.3 and 1.3.2 handle it properly ( albeit with Firefox sending an error ) but they still get the node right.

或者:您可以使用:text[value=]表示法,该表示法在我尝试过的任何地方都可以使用.只是有点怀疑而已.

Alternatively: you could use the :text[value=] notation, which appears to work everywhere I tried it. Its just a bit suspect thats all.

(忽略我以前的抱怨,他们都是胡扯,日子不好过-_-)

( Ignore my Previous rantings, they're all bollocks, not having a good day -_-)

这篇关于在Jquery中选择所有空文本字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆