jquery ?? ? ???(1)
? ???? ?? ??? ??? ????. ??? ??? ??? ?? ?? ?? ?? ???? ?? ?? ??? ???? ????. ?? ?? img ???? src? ??? ???? ???? ??? ???? ? ?????.
DOM? ?? ???? ?? getAttribute ???, setAttribute ???, RemoveAttribute ??? ? ??? ????. ???? ???? ?? ???? ??? ?? ??? ?? ???? ???? ??? ?????. jQuery??? attr()? RemoveAttr()? ???? ??? ??? ??? ?? ?? ??? ? ????.
jQuery?? attr() ???? ?? ??? ?? ???? ? ?????. jQuery?? attr? ??(attribute)? ?????. DOM Attr()
attr()?? 4?? ???? ????
attr(?? ?? ??): ?? ? ????
attr(?? ??, ?? ?): ?? ? ??
attr (???, ???) : ??? ???? ??
attr(attributes) : ??? ??? ?? ?? ???? ?????. ?, {??? 1 : "??? 1", ??? 2 : "?? ? 2”, … … }
removeAttr()Removal method
.removeAttr(attributeName): ???? ?? ??? ? ???? ??(attribute)? ?????
??:
attr ? RemoveAttr? ? ? ?? ??? ?? jQuery? ?? ??????. jQuery ???? ?? ? ???? ???? ??? ?? ??? ? ??? ?????? ?? ?? ??? ??? ??? ??? ??? ????
?? ??: ??
dom? ??? ?????. ??? ??? ?? "??"?? ???? "JS ?? ?????"??? ???? "??"? "??"?? ?????. ?? ???? Attribute? dom ??? ???? ?????
?: id, class, title, align ? HTML?? ?? ????
<div id="phpcn" title="php中文網(wǎng)"></div>
??? Property? ????? DOM ????, ?? ?? ?? tagName, nodeName, nodeType, defaultChecked ? defaultSelected? ?? ???? .prop() ???? ???? ?? ??? ???? ?? ??? ?????.
??? ???? attr? ???? ??, ??? ???? ??? ???? ???. prop
???? ????? ?? ?? ???????. ?? ?
??? ??? ????.
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> <title></title> <script src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script> </head> <body> <img src="1.jpg" width="200" height="200" id="img"> <script type="text/javascript"> $("#img").attr('width','400'); </script> </body> </html>
??: ?? ? ?? 1.jpg? ??? ???. ?? ?? ??? ?????
attr() ???? ???? ?? ?? ???? ??? ?? ?? ???
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> <title></title> <script src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script> </head> <body> <input type="text" value="php 中文網(wǎng)" id="ipt"> <script type="text/javascript"> alert($("#ipt").attr('value')); </script> </body> </html>
?? ??? ???? ??? php ?? ?????? ? ? ????
removeAttr() ?? ??? ??? ???? ??? ???????.
??? ??? ????.
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> <title></title> <script src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script> </head> <body> <input type="text" value="php 中文網(wǎng)" id="ipt"> <script type="text/javascript"> $("#ipt").removeAttr("value"); </script> </body> </html>
??: ?? ??? ???? ???? ??? ??? ? ??? ??? ????. ???