【发布时间】:2012-04-29 14:56:02
【问题描述】:
有没有更简洁的方法来做到这一点?
// exclude all HTML 4 except text and password, but include HTML 5 except search
var inputSelector = "textarea,input[type='text'],input[type='password'],input[type='color']," +
"input[type='date'],input[type='datetime'],input[type='datetime-local']," +
"input[type='email'],input[type='month'],input[type='number'],input[type='range']," +
"input[type='tel'],input[type='time'],input[type='url'],input[type='week']";
注意:我不能使用 .Not() 函数,因为该选择器将在 .delegate() 函数中使用。另外,最好让选择器默认包含未来的输入类型(HTML 6 >)。
答案:
这就是我现在所拥有的。比以前好多了。如果可以进一步完善,请告诉我。
// exclude all HTML 4 except text and password, but include HTML 5 except search
var inputSelector = "textarea,input:not([type='checkbox'],[type='radio'],[type='button']," +
"[type='image'],[type='submit'],[type='reset'],[type='file'],[type='search'])";
请注意,它还包括 input 和 textarea,这也意味着默认情况下将包括 HTML 规范的未来添加(对于那些认为不可能的人)。
【问题讨论】:
-
如果您需要特殊情况,那么您别无选择
-
.delegate()从什么时候开始不支持:not()? -
"另外,最好让选择器默认包含未来的输入类型 (HTML 6 >)。"你真的期望这样的选择器如何工作?
-
$("input:not([type='radio'], [type='text'])") .. 既然您的输入类型很少,为什么不包括在内使用那些?
标签: jquery jquery-selectors textinput