gpt4 book ai didi

jquery - 遍历 HTML : how can I hide a color when I move to another element?

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

当我移动到文档中的新元素时,它会被绘制,这没问题。但是当我离开那个元素时,我需要它来清除那个颜色并且应该跟随颜色按钮。我怎样才能做到这一点?感谢您的帮助!

这是一个示例链接:http://jsfiddle.net/centerwow/9TPtn/10/

HTML代码:

<ul>ul1
<li>1</li>
<li>2</li>
<li class="point_me">3</li>
<li>4</li>
<li>5</li>
</ul>
<ul>ul2
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ul>

<br/>

<div>
<p id="Pr"><button>Prev</button></p>
<p id="Ne"><button>next</button></p>
<p id="Si"><button>siblings</button></p>
<p id="Ch"><button>children</button></p>
<p id="Pa"><button>parent</button></p>
</div>

CSS 代码:

div, li {
width:40px; height:40px; margin:10px;
float:left; border:2px blue solid;
padding:2px;
}

ul {
width:100px; height:10px; margin:10px;
float:left; border:2px blue solid;
padding:2px;
}

span {
font-size:14px;
}

p {
clear:left; margin:10px
}​

jQuery 代码:

var $elm = $(".point_me");
$elm.css("background", "#cac");

$("#Pr").click(function() {
$elm = $elm.prev();
$("div").css("background", "");
$elm.css("background", "#cac");
});

$("#Ne").click(function() {
$elm = $elm.next();
$("div").css("background", "");
$elm.css("background", "#cac");
});

$("#Si").click(function() {
$elm = $elm.siblings();
$("div").css("background", "");
$elm.css("background", "#cac");
});

$("#Pa").click(function() {
$elm = $elm.parent();
$("div").css("background", "");
$elm.css("background", "#cac");
});​

最佳答案

请更好地描述您的问题。

这是你想要的吗?

http://jsfiddle.net/9TPtn/11/

function resetColor(){
$('li').css("background","transparent");
}

关于jquery - 遍历 HTML : how can I hide a color when I move to another element?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9452585/

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