点击切换帐号登陆
帐号密码登陆

jQuery操作属性方法

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>jquery第十节课</title>
	<script type="text/javascript" src="jquery-3.3.1.min.js"></script>
  <script type="text/javascript">
   $(function(){
   //jQuery操作属性方法
    //attr() 方法设置或返回被选元素的属性值;
    console.log($('a').attr('href'))
    //$('a').attr('class','box')
    // 同时设置多个属性
    // $('选择器').attr({属性名:值, 属性名:值 ...})
    $('a').attr({class:'box',id:'box'})
    //removeAttr()从被选元素中移除属性;  
    $('p').click(function(){
      $(this).removeAttr('class','text')
    })
   })

  </script>
  <style type="text/css">
  *{margin:0;padding:0;}
  p,div{margin:20px auto;text-align: center;}
  div{width:300px;height:50px;line-height: 50px;}
  p{width:300px;height:300px;line-height: 300px;background:#9BF25A;}
  .box{padding: 8px;background: #ff6500;text-decoration: none;}
  #box{color: #fff;}
  .text{font-size: 30px;color: #fff;}
  </style>
</head>
<body>
  <div>
    <a href="0133.cn"> HTML 中文网!</a>
    <p class="text">~ 鼠标移上有惊喜 ~</p> 
  </div>
</body>
</html>


任务

?不会了怎么办
无数据提示暂无评论哟...我要评论
网站导航
标签地图
学习路径
视频教程
开发软件
旗下子站
php中文网
phpstudy
技术文章
文档工具
关于我们
企业合作
人才招聘
联系我们
讲师招募
QQ交流群
QQ官方交流群
微信公众号
微信公众号