1

有没有更简洁的方法来做到这一点?

// 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'])";

请注意,它还包括输入和文本区域,这也意味着默认情况下将包括对 HTML 规范的未来添加(对于那些认为不可能的人)。

4

3 回答 3

1

It seems like the delegate() method does not work well when the selector is not a string. 要解决这个问题,只需将您的逻辑放在您的委托处理程序中

//Input types I do not want to select
var typeArray = ["text", "date"];

$("form").delegate("input", "click", function() {
    if($.inArray(this.type, typeArray) === -1) {
        //Put your logic here
    }
});
于 2012-04-29T15:23:40.690 回答
0

如果要过滤掉多种类型,可以执行以下操作:

$('input[type!="radio"][type!="text"]')
于 2012-04-29T15:38:00.880 回答
0

MДΓΓ БДLL 和 xFortyFourx 都给了我这个解决方案,结果证明这是我正在寻找的最佳答案,但不知道为什么它在评论而不是答案中得到了回答。

$("input:not([type='radio'], [type='text'])")
于 2012-04-29T15:34:09.630 回答