作者gaekeamql (芋头)
看板Ajax
标题[心得] id重复的问题...
时间Thu Jul 21 15:29:41 2011
正常来讲网页id是不应该重复的
但是不小心还是会给他用到
如果这个时候 我有试 opera chrome ie8
例如:
<div class=aaa id=r1>123</div>
<div class=bbb id=r1>456</div>
此时 opera & chrome
jquery
$('.aaa#r1').html();
$('.bbb#r1').html();
此时 ie8 是不认识 第二个
都可以用的用法可以写
$('.aaa[id=r1]').html();
$('.bbb[id=r1]').html();
不知道该说IE遵守标准还是.......
一定要把id搞一样可以做
<div id=r1>
<div class=aaa>123</div>
<div class=bbb>456</div>
</div>
jquery
$('#r1').find('.aaa').html();
$('#r1').find('.bbb').html();
这样是比较正统的写法
有错请多指教,我还很嫩!!..谢谢
--
█ █ █ http://www.u-tao.tw
█ █ ███ ▄▄█▄ ▄ ▄
█ █ █ █ ▉ █ ▉
█ █ █ █ ▉ █ ▉
◥▇▇▇◤ █ ◢ █ ▋▊ █ ▉
██ ▊█ ◥ ▍█
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 59.120.250.11
1F:→ st900278:id 在一份html里面 只能出现一次喔 07/21 15:57
2F:→ st900278:就像是不会有两个人有同个身分证一样 id 不能重复 07/21 15:58
3F:推 senser:id就是设计成要unique的 为什麽要这样用哩? 07/21 17:33
4F:→ mesak:最後一个可以这样写 $('#r1 > .aaa').html() 07/21 23:41
5F:→ gaekeamql:喔!...有在jquery 有看到..刚刚才发现...=.=.感谢分享. 07/21 23:45
6F:→ gaekeamql:会这样写id实在都是不得已的!. .=.=. 07/21 23:47
7F:推 senser:>是CSS常用的选择符 jquery也可以用.children([selector]) 07/24 06:46