javascript文件中出现错误
我试图找出这段代码中的错误。这是为了使搜索表单隐藏,然后仅在我单击搜索按钮时显示。它起了作用,但最终影响了导航栏,如果我单击任何内容,页面将不会加载,除非我在新选项卡中打开它。查看开发人员控制台,您会看到错误javascript文件中出现错误,javascript,Javascript,我试图找出这段代码中的错误。这是为了使搜索表单隐藏,然后仅在我单击搜索按钮时显示。它起了作用,但最终影响了导航栏,如果我单击任何内容,页面将不会加载,除非我在新选项卡中打开它。查看开发人员控制台,您会看到错误未捕获的语法错误:意外标记。这是因为您错过了选择器字符串上的开头” function () { $('body, .navbar-collapse div[role="search"] button[type="reset"]') .on('click keyup'
未捕获的语法错误:意外标记。
这是因为您错过了选择器字符串上的开头”
function ()
{
$('body, .navbar-collapse div[role="search"] button[type="reset"]')
.on('click keyup', function (event) {
event.preventDefault();
if (event.which == 27 && $('.navbar-collapse div[role="search"]')
.hasClass('active') ||
$(event.currentTarget).attr('type') == 'reset') {
closeSearch();
}
});
closeSearch();
function closeSearch() {
$('#navbar-searchform, #navbar-reset').addClass('hidden');
var $form = $('.navbar-collapse div[role="search"].active')
$form.find('input').val('');
$form.removeClass('active');
$('#navbar-search').removeClass('hidden');
}
// Show Search if form is not active // event.preventDefault() is important, this prevents the form from submitting
$(document).on('click',.navbar-collapse div[role="search"]:not(.active) button[type="submit"]',
function (event) {
event.preventDefault();
var $form = $(this).closest('div[role="search"]'),
$input = $form.find('input');
$form.addClass('active');
$('#navbar-searchform, #navbar-reset')
.removeClass('hidden'); $input.focus();
$(this).addClass('hidden');
});
$(文档)。在('click')上,导航栏折叠div[role=“search”]:非(.active)按钮[type=“submit”]“,
这一行应该会在开发人员控制台中显示一条错误消息。为什么不以打字错误的形式关闭?问题在评论中得到了回答,我是写评论的人……我以打字错误的形式关闭了它……我回答了它……现在我发表了评论。;)
$(document).on('click',.navbar-collapse div[role="search"]:not(.active) button[type="submit"]',
^^^