gpt4 book ai didi

javascript - 选择时更改背景颜色

转载 作者:行者123 更新时间:2023-11-28 07:56:28 25 4
gpt4 key购买 nike

我已经创建了导航,您可以在其中使用箭头键选择导航,但我仍然需要取消对 #header_search_bar_input 的关注并更改用户选择的导航的背景。

网站: http://gyazo.com/68cd4fa85a42e604a35ab25548d15235

JS:

var selected = 0;


$(window).keydown(function(e){
var lenght = $('[id^=fclink_]').length;

if(e.which === 40){
selected++;
if(selected > lenght) {
selected = 0;
}
}else if(e.which === 38){
selected--;
if(selected < 0) {
selected = lenght;
}
}else if(e.which === 13){
string = '#fclink_';
num = selected.toString();
var href = $(string.concat(num)).attr('href');
window.location.href = href;
}

if(selected == 0) {
document.getElementById('header_search_bar_input').focus();
} else {

}
});

HTML:

<li id="header_search_bar_container">
<ul id="header_search_bar">
<form action="index.php" method="post">
<input type="text" name="search_query" id="header_search_bar_input" autocomplete="off" onkeyup="autosuggest()">
<input type="submit" id="header_search_bar_submit" value="">
</form>
</ul>
<div id="header_show_auto_suggest"><a href="forecast.php?location=3" id="fclink_1">
<ul id="header_search_bar_auto_suggest" style="border-top: solid 1px #dddddd;" class="fcfocus_1">
<p id="header_search_bar_text">
Akranes, Iceland
</p>
<img src="images/flags/IS.png" id="header_search_bar_img" width="28px" height="28px">
</ul>
</a><a href="forecast.php?location=1" id="fclink_2">
<ul id="header_search_bar_auto_suggest" class="fcfocus_2">
<p id="header_search_bar_text">
Akureyri, Iceland
</p>
<img src="images/flags/IS.png" id="header_search_bar_img" width="28px" height="28px">
</ul>
</a><a href="forecast.php?location=2" id="fclink_3">
<ul id="header_search_bar_auto_suggest" class="fcfocus_3">
<p id="header_search_bar_text">
Reykjavík, Iceland
</p>
<img src="images/flags/IS.png" id="header_search_bar_img" width="28px" height="28px">
</ul>
</a></div>
</li>

请告诉我更改背景颜色的正确方法。

最佳答案

当您在代码中使用 jQuery 时,这里是更改背景颜色的 jQuery 方法:

$("yourselector").css("background-color", "red");

关于javascript - 选择时更改背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30088171/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com