7.1.5 jQuery的属性操作

1. html属性操作: 是对文档中的属性进行操作

2. dom属性操作

3. 类样式操作

4. 值操作

======

1.  标签的属性操作

<body>

<script type="text/javascript" src="jquery-3.3.1.js"></script>

<script type="text/javascript">

1. 样式属性操作css('color')获取值

css('color','red') 设置单个值

css({

  key1:value1,

  key2:value2

});

key既可以是驼峰,又可以是margin-left 要给margin-left加引号

2. 标签的属性操作

  attr(key) 获取属性值 

  attr(key,value)设置单个值

  attr({key1:value1,key2:value2}); 设置多个值

 

3. DOM对象属性操作

 

4. 类样式属性操作

addClass()  removeClass()  toggleClass()

 

5. 对值的操作

text()  html()  val()

 

innerText

innerHTML

value

 

6. 对DOM的操作 CRUD 增删改查

 

js中:

setAttribute(key,value)

getAttribute()

  $function(){

    //attr() 有一个参数表示获取属性值

    console.log($('div').attr('title'))

    $('div').attr('id','box');

    //设置属性的时候不要使用此方式来设置类名,使用addClass或removeClass

    $('div').attr('class','box1 box2');

   

    $('a').attr({

      "href":"https://www.baidu.com".

      'title':'哈哈哈'

      })

    //移除标签的属性

    $('div').removeAttr('title id');

  }

</script>

</body>

 

posted @ 2018-09-14 17:21  beallaliu  阅读(103)  评论(0编辑  收藏  举报