点击第五个li和第五个input alert(1),点其它地方没反应
<body>
<ul><li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ul>
<input type="button" value="1" />
<input type="button" value="2" />
<input type="button" value="3" />
<input type="button" value="4" />
<input type="button" value="5" />
<script type="text/javascript">
$(function(){
$('body').on('click',function(e){
var list = $('li:nth-child(5)').add($('input:nth-child(5)')); //把不相关的两个元素放在一个数组
var target = e.target;
var b = $.inArray(target,list); //判断点击的元素是否在数组里面 ,在就返回位置,不在返回-1;
if(b!=-1){
alert(1);
}
});
})
</script>
</body>