在下面的代码中,我如何执行测试,并知道点击了哪个元素?
$("li,p").click(function(){
// how do I perform a test, and know which Element it is?
if( /* I'm a <li/> */ )
// Do this for the <li/>
if( /* I'm a <p/> */ )
// Do this for the <p/>
})
最佳答案
一个选择是使用 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/>
})
关于javascript - 我是谁或者我怎么知道我正在处理的是哪个元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5378549/