我希望在调用函数以通过 XML 搜索以匹配单词时更改光标,以便用户知道正在发生某些事情。
这是功能:
function searchResults(query) {
$("body").css("cursor", "wait");
var temp = "\\b" + query + "\\b";
var regex_query = new RegExp(temp, "gi");
var currentLine;
var num_matching_lines = 0;
var searchCount = 0;
var matchesLine;
$("#mainOutput, #searhResults").empty();
$("LINE", currentContext).each(function () {
var line = this;
currentLine = $(this).text();
matchesLine = currentLine.replace(regex_query, '<span class="query_match">' + query + '</span>');
if (currentLine.search(regex_query) > 0) {
searchCount = searchCount + currentLine.match(regex_query).length;
$('#sideInfo>ul').empty();
num_matching_lines++
$("#mainOutput").append("<br /><p class='speaker_match indent'>"+ $(line).parent().find('SPEAKER').text() +"</p>");
$("#mainOutput").append("<p class='act_match indent'>"+ $(line).parent().parent().parent().children(':first-child').text()+"</p>");
$("#mainOutput").append("<p class='scene_match indent'>"+ $(line).parent().parent().children(':first-child').text() +"</p>");
$("#mainOutput").append("<p class='pad'>" + matchesLine + "</p>");
$("#mainOutput").append("<br><hr />");
}
});
$("#searhResults").append("<p>Found " + query + " in " + num_matching_lines + " lines</p>");
$("#searhResults").append("<p>Found " + query + " " + searchCount + " times</p>");
$("body").css("cursor", "default");
}
它由以下任一操作调用:
$("#term_search").keypress(function (event) {
if (event.keyCode == 13) searchResults($("#term_search").val());
});
$('#term-search-btn').click(function () {
searchResults($("#term_search").val());
});
问题是搜索完成后光标变为等待符号,然后没有变回默认值,我该如何解决这个问题?