Examples:
Example: Set some attributes for all <img>s in the page.
<!DOCTYPE html>
<html>
<head>
<style>
img { padding:10px; }
div { color:red; font-size:24px; }
</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<img />
<img />
<img />
<div><B>Attribute of Ajax</B></div>
<script>
$("img").attr({
src: "/images/hat.gif",
title: "jQuery",
alt: "jQuery Logo"
});
$("div").text($("img").attr("alt"));
</script>
</body>
</html>
给标签 添加元素
$('#greatphoto').attr('alt', 'Beijing Brush Seller');
删除元素
$("img").removeAttr("src");
得到元素值
$("img").attr("src");
转载:http://api.jquery.com/attr/