开发者

function/selector to filter inputs by value

Is there a built-in function/selector in jQuery to开发者_JAVA技巧 filter the inputs by value?

I can create a custom selector:

$.extend($.expr[":"], {
    val: function(elem, index, match) {
       return $(elem).val() == match[3];
    }
});

and use it like this: $("input:val('Some text')").

I was just wondering if something like this already exists or maybe there is a better way.


It doesn't look like there's a built-in solution. But for a one-off selector, .filter() is an option:

$('input').filter(function() { return $(this).val() === 'Some text'; });


You can do this:

    $('input[value=someval]')

you can also chain it

    $('input[type=radio][value=someval]')

look here:


$.extend($.expr[":"], {
    val: function(elem, index, match) {
       return $.trim($(elem).val()) == $.trim(match[3]);
    }
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜