jquery选择器性能

Hus*_*ein 3 performance jquery jquery-selectors

是否有更高效的方式来写这个.

$('#test').find('option:selected[value!=""]')
Run Code Online (Sandbox Code Playgroud)

jAn*_*ndy 5

您可以稍微调整它,但使用方法而不是Sizzle:

$('#test').find('option').filter(function() {
    return this.selected && this.value.length
});
Run Code Online (Sandbox Code Playgroud)

基准:http://jsperf.com/sizzle-vs-methods-filter/12

.filter() 对我来说快了约70%.