批改狀態(tài):未批改
老師批語:
attr函數(shù)和removeatter函數(shù)的定義和用法:
1、attr主要用于增加,獲取兩個功能,常見方法為:
獲取:var res=$('li').attr('width')
//以上方法獲取使得變量red獲取到了li的寬度
增加:
$('li').attr('width',' 300px')
//以上方法為li增加了一個300px的寬度
增加多個(使用空格隔開)
$('li').attr('style','boder: 1px boder-raidus:50% box-shadow: 5px 5px 5px red')
//以上方法為li增加了多個樣式變化
刪除多個
$('*').removeAttr('src charset alt style border width height ')
以上方法提供了多個樣式的刪除
代碼部分:
<!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta http-equiv="X-UA-Compatible" content="ie=edge" /> <title>Document</title> </head> <body> <img src="img/001.jpg" alt="寶寶圖片" width="150" height="150"/> </body> <script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js" type="text/javascript" charset="utf-8"></script> <script type="text/javascript"> $('img').attr('width','300px') //為img增加一個寬度,為300PX $('img').removeAttr('src') //移除屬性src $('img').attr('src','img/001.jpg') //增加一個屬性src、并修改圖片路徑 $('img').attr('style','border-radius: 50%; box-shadow: 50px 50px 50px darkgrey;') //多個修改元素,用空格進行隔開即可 var bss=$('img').attr('width') //用于獲取,變量bss獲取了img的寬度 $('*').removeAttr('src charset alt style border width height ') //移除多個屬性,用空格隔開即可 </script> </html>
點擊 "運行實例" 按鈕查看在線實例
微信掃碼
關(guān)注PHP中文網(wǎng)服務(wù)號
QQ掃碼
加入技術(shù)交流群
Copyright 2014-2025 http://ipnx.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號