我有一个Google即时样式的jQuery搜索脚本,用于查询PHP文件,然后将结果解析为HTML div。当没有查询处于活动状态时,将自动选择文本框,但当查询处于活动状态时,我希望不会自动选择该查询。我知道这可以通过使用.blur();
函数来实现,但是当查询处于活动状态并且页面已被重新加载时,如何才能使其仅使用.blur();
函数?我希望每个人都能理解我的问题。如果内容处于活动状态,在页面重新加载后取消选择jQuery中的文本框
我jQuery代码是:
$(document).ready(function() {
$('[id^=type_]').click(function() {
type = this.id.replace('type_', '');
$('[id^=type_]').removeClass('selected');
$('#type_' + type).addClass('selected');
return false;
});
$('#query').focus();
if (window.location.hash != "") {
var full = window.location.hash.replace('#', '');
var queryType = full.substring(0, full.indexOf("/"));
$('#type_' + queryType).click();
} else {
$('#type_search').click();
}
$('#query').keyup(function() {
var query = $(this).val();
var url = '/' + type + '/' + query + '/';
window.location.hash = '' + type + '/' + query + '/';
document.title = $(this).val() + ' - My Search Script';
$('#results').show();
if (query == '') {
window.location.hash = '';
document.title = 'My Search Script';
$('#results').hide();
}
$.ajax({
type: 'GET',
url: url,
dataType: 'html',
success: function (results) {
$('#results').html(results);
}
});
});
if (window.location.hash.indexOf('#' + type + '/') == 0) {
query = window.location.hash.replace('#' + type + '/', '').replace('/', '');
$('#query').val(decodeURIComponent(query)).keyup();
}
});
通过“激活查询”你指的是具有#视频/诸如此类的东西在它的网址是什么?或者你的意思是别的吗? –