如何获取多个属性值?我可以href
正确得到,我也想得到alt
,但我无法正确计算并得到正确的结果。.attr('href').attr('alt')
.attr('href' + 'alt')
我也试过了.attr({href, alt})
,
这是在线示例:http: //jsfiddle.net/Lm4TM/
JS:
$(document).ready(function(){
$(".link").each(function (i) {
var links = $(this).find("a");
$(this).wrapInner("<a href='"+ $(links).attr('href') + "'></a>");
});
});
CSS:
.link {
width:20%;
height: 100%;
background: red;
float: left;
margin: 0 20px;
}
a {
text-decoration: none;
color: white;
}
HTML:
<div class="link">
<a href="http://www.google.com" alt="google">Google.com</a>
<p> Google Inc. is an American multinational corporation that provides Internet-related products and services, including internet search, cloud computing, software and advertising technologies.Advertising revenues from AdWords generate almost all of the company's profits</p>
</div>
<div class="link">
<a href="http://www.microsoft.com" alt="microsoft">Microsoft.com</a>
<p>Microsoft Corporation is an American multinational software corporation headquartered in Redmond, Washington that develops, manufactures, licenses, and supports a wide range of products and services related to computing.</p>
</div>
<div class="link">
<a href="http://www.Apple.com" alt="Apple">Microsoft.com</a>
<p>The apple is the pomaceous fruit of the apple tree, species Malus domestica in the rose family (Rosaceae). It is one of the most widely cultivated tree fruits, and the most widely known of the many members of genus Malus that are used by humans.</p>
</div>