返回列表 發帖

請問要如何選取一個元素下面的id值呢?

<div id="a">
<img src="abc.jpg" id="b" />
</div>
$("#a > img");
我只能選到下一層的物件
不知該如何取出id值b呢

下面是你要的
$("#a > img").attr('id') 

TOP

請問要如何使用關鍵字this呢
  $("this > img").attr('id')   
不行
  $(this > img).attr('id')
也不行

TOP

$(this) 是在 jQuery 的 callback function 裡面用的
$("#a > img").click(function () {
  alert($(this).attr("id"));
});
To infinity and beyond!

TOP

返回列表 回復 發帖