を取得する私は、次の検索機能を持っている:私は関数の内部でそれを作成したのでが変数jquery.eachのOUT()関数
function filter() {
$("table#list tr").each(function() {
var search = $("#search").val();
var name = $(this).find("span.name").html();
var email = $(this).find("span.email").html();
var ref = $(this).find("span.reference").html();
var match = false;
var count = 0;
if((name != undefined) && (email != undefined) && (ref != undefined)) {
if(name.indexOf(search) >= 0) match = true;
if(email.indexOf(search) >= 0) match = true;
if(ref.indexOf(search) >= 0) match = true;
if(match) {
$(this).removeClass("collapse");
count++;
} else {
$(this).addClass("collapse");
}
}
});
$("#result-count").html(count + " results found.");
}
は、しかし、最後の行に、count
は、未定義です。 $ .each関数の外で値を取得するにはどうすればよいですか?
編集:ループ内のカウントをリセットしているので、常に0になることもわかりました。どうすれば結果を適切にカウントできますか?
が置か 'VARカウント= 0;'外'.each()' – guradio