作者DRLai (苏打)
看板Ajax
标题[问题] jquery可以判断id是否存在吗?
时间Wed May 13 22:13:33 2009
我写了一个程式
有个东西不知道该怎麽写...
我使用jquery写了类似以下功能
当我click在某个物件上时
他会去找该物件的id後面加上"_2"并对他产生事件
$(".aaa").click( function() {
$( "#"+this.id+"_2" ).show();
} );
然而现在产生一个问题
有办法先判断this.id + "_2"这个id是否存在吗
当不存在时,我要对这个id作另外的处理
感谢^^"
--
▊ ◥ thePainter. ◤ ▎
▊ ◣◢ ◣ ◤
◣ ◤
▎
▊ ◥
◤ ◣ ◤
◤
▎ http://www.wretch.cc/blog/myelf
▊ ◥
◢ ◤ ◤
◤ ▎ Wretch@BBS -> P_myelf
▊ ◢◤
thePainter. ◣ ▎ φthePainter.
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.138.145.212
1F:推 TonyQ:if( $("#"+this.id+"_2").size()!=0){ /*....*/} 05/13 22:16
2F:→ DRLai:原来是使用size()阿...感谢T大m(_ _)m 05/13 22:22
3F:→ lailai9:$("#"+this.id+"_2").length也可以的 05/17 00:21