嘿,看看这段代码:
$("li,p").click(function(){
// how do I perform a test, and know wich Element it is ?
if( /* I'm a <li/> */ )
// Do this for the <li/>
if( /* I'm a <p/> */ )
// Do this for the <p/>
})
Run Code Online (Sandbox Code Playgroud)
谢谢你们^^
一种选择是使用is()方法:
$("li,p").click(function(){
// how do I do I perform a test, on wich Element it is ?
if($(this).is('li'))
// Do this for the <li/>
if($(this).is('p'))
// Do this for the <p/>
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
490 次 |
| 最近记录: |