jQuery学习笔记(二)——css与节点操作

一、获取和设置元素内容

1、$('#box').html()、$('#box').html('<p>123</p>')    html内容

2、$('#box').text()、$('box').text('123')          文本内容

3、$('#box').val()、$('#box').val('123')           表单内容

二、元素属性操作

1、$('#box').attr('id')      取得id值

2、$('#box').attr('name','user')  设置属性

3、$('#box').attr({        设置属性

    name:user;

    title:hao;

    class:red

   })

4、$('#box').removeAttr('title')  删除属性

三、元素样式操作

1、$('#box').css('color','red')      设置颜色

2、$('#box').css({

  'color':'red';

  'width':'200px';

  'height':'100px'

})

3、$('#box').addClass('red')    添加class

4、$('#box').removeClass('red')  删除class

5、$('#box').toggleClass('red')  切换class

其他方法

1、$('#box').width()、$('#box').width('200px')    获取和设置高度

2、$('#box').height()、$('#box').height('200px')    获取和设置高度

3、$('#box').offset()              获取某个元素相对于视口的偏移位置(点对象)

4、$('#box').position()            获取某个元素相对于父元素的偏移位置(点对象)

5、$('#box').scrollTop()、$('#box').scrollTop('200px')

6、$('#box').scrollLeft()、$('#box').scrollLeft('200px')

 

posted @ 2015-11-21 12:03  Bishar  阅读(205)  评论(0编辑  收藏  举报