ITPub博客

首页 > > > 请问各位大神关于div选中效果的事

请问各位大神关于div选中效果的事

作者:dapan 时间:2019-09-02 15:37:27 0 删除 编辑
下面是border的部分:

<div class="demo">
  <div>中国</div>
  <br/>
  <div>俄国</div>
  <br/>
  <div>泰国</div>
</div>

下面是CSS部分:

.demo div{
  text-align: center;
  line-height: 40px;
  font-weight: bold; 
  border:1px solid #BDCFE4;
  border-radius: 300px;
  margin: 0 auto;
  width: 200px;
  height: 40px;
  border: 1px solid #003BB3;

}

下面是Jquery部分:

$(function(){ 

  $(".demo div").mouseover(function(){
    $(this).css("background-color","#149BDF");
    $(this).css("cursor","pointer")
  })//移入背景变淡蓝色


  $(".demo div").mouseout(function(){
    $(this).css("background-color","white");
  })//移出恢复白色背景色

})

是这样的,我想让class=demo的div里面的3个子div(中国,俄国,泰国这三个div)点击后背景色跟移入的背景色一样,点击另一个div后背景色跟移入的背景色一样,但之前点击过的div背景色恢复成白色背景色

请问要怎么做?(里面的div不要去添加ID)


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/758/viewspace-3133700/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2020-08-07

  • 博文量
    4504
  • 访问量
    87279