亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

jQuery manipulating element attributes

jQuery operates element attributes

We can use getAttribute and setAttribute in javascript to operate the "element attributes" of the element.

In jQuery provides you with the attr() wrapping set function, which can simultaneously operate the attributes of all elements in the wrapping set:

QQ截圖20161026094540.png

When using the id selector, only one object is often returned. jQuery wrapper set, at this time the attr(name) function is often used to obtain its element attributes:

function testAttr1(event) {    
         alert($("#hibiscus").attr("class"));    
    }

Note that the attr(name) function only returns the specific element attribute value of the first matching element. And attr(key , name) will set the element attributes of all packaging sets:

//修改所有img元素的alt屬性    
$("img").attr("alt", "修改后的alt屬性");

and attr( properties ) can modify multiple element attributes at one time:

  $("img").attr({title:"修改后的title", alt: "同時(shí)修改alt屬性"});

In addition, although we can use removeAttr( name ) delete element attributes, but the corresponding DOM attributes will not be deleted, and will only affect the value of the DOM attribute.

For example, removing the readonly element attribute of an input element will cause the corresponding DOM attribute to become false (that is, the input becomes editable):

   $("#inputTest").removeAttr("readonly");


Continuing Learning
||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Jquery 動(dòng)態(tài)修改連接</title> <script src="http://code.jquery.com/jquery-3.1.1.min.js"></script> <!--上面更換您的jquery 路徑--> </head> <style> span{display:block; width:100px; margin:0 20px 15px 0; text-align:center; height:20px; line-height:20px; display:block; float:left; background:#CCC;} div{border:#000 solid 1px; height:30px; clear:left; width:300px; line-height:30px; text-align:center;} </style> <script> var link1 = "<a target='_blank'>";//聲明一個(gè)變量 var link2 = "<a target='_blank'>"; var link3 = "<a target='_blank'>"; var linkR = "</a>";//連接結(jié)束 $(function(){ $("#link1").hover(function(){ $("#test").html(link1+"連接文字"+linkR);//修改指向時(shí)的連接 }) $("#link2").hover(function(){ $("#test").html(link2+"連接文字2"+linkR); }) $("#link3").hover(function(){ $("#test").html(link3+"連接文字3"+linkR); }) }) </script> <body> <span id="link1">1</span> <span id="link2">2</span> <span id="link3">3</span> <div id="test"></div> </body> </html>
submitReset Code