Blogger Information
Blog 23
fans 1
comment 1
visits 23100
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
将attr()和css()方法的完整用法-4月4日作业
潮涌学习php的博客
Original
794 people have browsed it

.attr:获取和css属性

1、var res = $('#pic').attr('src')   返回src值,即图片地址

$('#pic').attr('src','../images/gyy.jpg')  将图片替换为gyy.jpg。第一个为属性名,第二个为要设置的值

2、attr可以获取到自定义的data-前缀的自定义属性

var res = $(#pic).attr('data-nation')

3、attr支持回调函数

$('#pic').attr('width',function(){

    return 100+50

})

4、删除属性

$('#pic').removeAttr('style')

--------------------------------------------------------------

.css()   主要是设置样式

var res = $('img').css('width',200)

链式操作:

var res = $('img').css('width',200).css('border-radius','10%').css('box-shadow','5px 5px 5px #888')

var res = $('img').css({

'width':'200px',

'border-radius':'10%',

'box-shadow':'5px 5px 5px #888'

})

4.4.1.jpg

4.4.2.jpg

4.4.3.jpg

4.4.4.jpg

4.4.5.jpg

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post