Javascript JS/HTML:向搜索输入的父级添加类不起作用
您好,我正在尝试选择搜索输入的父DIV,以便在搜索输入聚焦时更改背景颜色。我不明白为什么这个代码不起作用。谢谢你的帮助 HTML JAVASCRIPTJavascript JS/HTML:向搜索输入的父级添加类不起作用,javascript,jquery,html,css,Javascript,Jquery,Html,Css,您好,我正在尝试选择搜索输入的父DIV,以便在搜索输入聚焦时更改背景颜色。我不明白为什么这个代码不起作用。谢谢你的帮助 HTML JAVASCRIPT $(function(){ $('.box').focus(function(){ $(this).parent().addClass('fill'); )}; 语法错误很多 )}; //mismatched order 应该是 }); }); //you also forgot to close DOM
$(function(){
$('.box').focus(function(){
$(this).parent().addClass('fill');
)};
语法错误很多
)}; //mismatched order
应该是
});
}); //you also forgot to close DOM ready handler
还可以尝试使用小提琴顶部的“JSHint”按钮
好的IDE也会为您强调这些错误。另外,使用适当的缩进有助于查找未关闭的处理程序:
$(function () {
$('.box').focus(function () {
$(this).parent().addClass('fill');
});
});
上面的格式是使用jsfiddle的“TidyUp”按钮获得的。这是您的。语法错误
)}; //mismatched order
应该是
});
}); //you also forgot to close DOM ready handler
还可以尝试使用小提琴顶部的“JSHint”按钮
好的IDE也会为您强调这些错误。另外,使用适当的缩进有助于查找未关闭的处理程序:
$(function () {
$('.box').focus(function () {
$(this).parent().addClass('fill');
});
});
上面的格式是使用jsfiddle的“TidyUp”按钮获得的。这是你的。你的JS中有一个打字错误,应该是这样的
$(function(){
$('.box').focus(function(){
$(this).parent().addClass('fill');
});
});
你的JS中有一个输入错误,应该是这样的
$(function(){
$('.box').focus(function(){
$(this).parent().addClass('fill');
});
});
看起来你有语法错误。以下是正确的代码:
$(function(){
$('.box').focus(function(){
$(this).parent().addClass('fill');
});
});
看起来你有语法错误。以下是正确的代码:
$(function(){
$('.box').focus(function(){
$(this).parent().addClass('fill');
});
});
试试这个
$(function(){
$('.box').focus(function(){
$(this).parent().addClass('fill');
});
});
试试这个
$(function(){
$('.box').focus(function(){
$(this).parent().addClass('fill');
});
});
您的JavaScript中有一个错误: 更改此项:
$('.box').focus(function(){
$(this).parent().addClass('fill');
)};
致:
(注意翻转的大括号顺序)JavaScript中有一个错误: 更改此项:
$('.box').focus(function(){
$(this).parent().addClass('fill');
)};
致:
(注意大括号的翻转顺序)
它的背景色是
背景色
不是背景色
它的背景色是背景色
不是背景色