2009年10月14日 14:25
1.核心
each() 函数使用
如:
$("body img").each(function){
alert($(this).text())
})
循环查找body标签下面所有的img元素。
2.属性
attr : 取得第一个匹配元素的属性值。通过这个方法可以方便地从第一个匹配元素中获取一个属性的值。如果元素没有相应属性,则返回 undefined
如:

var some_var = $("p img").attr('src');
则 some_var 值为:http://www.baidu.com/logo.gif
removeAttr:从每一个匹配的元素中删除一个属性
如:

$("p img").removeAttr("title")
延伸使用:
function resize_container_image_size(some_div_id,max_width){
$("#"+some_div_id+" img").each(function(){
if($(this).width() > max_width){
$(this).width(max_width);
$(this).removeAttr("height");
}
})
}