jQuery search val() in multiple textboxes
What's the most efficient way to loop though all textboxes for searching for a specific value and not using each()
开发者_高级运维?
Always know your selectors.
$('input:text[value="search text"]'); // exact
$('input:text[value*="search text"]'); // contains
Probably nothing wrong with using .each
, as you're going to have to perform a loop no matter what, but you could use filter()
, which may be shorter and a bit more expressive:
$("input").filter(function() { return this.value === "value"; });
You could use map instead, especially if you plan to store results from each textbox in an array as map does that by default (return value from the mapped method gets stored)
var resultArray = $.map(selection, function(item) { return xxxx; });
精彩评论