<!DOCTYPE html>
<html>
<head>
<script src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>
</head>
<style>
.selected{background:yellow;}
</style>
<body>
<div><span>Hello</span></div>
<input id=s1 type=button value='ww'>
<input id=s2 type=button value='xx'>
<input id=s3 type=button value='xx'>
<script>
$(document).ready(function(){
$("#s1").click(function(){
$("#101").addClass('selected').siblings().removeClass('selected');
})});
$(document).ready(function(){
$("#s2").click(function(){ $("#102").addClass('selected').siblings().removeClass('selected');
})});
$(document).ready(function(){
$("#s3").click(function(){ $("#103").addClass('selected').siblings().removeClass('selected');
})});
</script>
</body>
</html>
$("#101").addClass('selected').closest('li').siblings().children().removeClass('selected');
ID最好加上引号。
$("#101").addClass('selected').parent().siblings().children().removeClass('selected');
你的代码写的我都不想评论了,,你的id class能不能加个引号啊,,还有你代码中间加个图片是干啥啊,,别人想测试都麻烦。
代码写的真糙……
<!DOCTYPE html>
<html>
<head>
<script src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>
</head>
<style>
.selected{background:yellow;}
</style>
<body>
<div><span>Hello</span></div>
<input id=s1 type=button value='ww'>
<input id=s2 type=button value='xx'>
<input id=s3 type=button value='xx'>
<script>
$(document).ready(function(){
$("#s1").click(function(){ $("#101").addClass('selected').siblings().removeClass('selected');
$("#s2").click(function(){ $("#102").addClass('selected').siblings().removeClass('selected');
$("#s3").click(function(){ $("#103").addClass('selected').siblings().removeClass('selected');
});
</script>
</body>
</html>
多看看教程;熟练使用;
这个问题我在另外一个问题里已经回答过了 。。都是你。。。一模一样的。。。。你还开2个问题。。。
https://.com/q/1010000004517183?_ea=638049