猿问

$(event.target)???

<!DOCTYPE html>
<html>
<head>
  <script type="text/javascript" src="/jquery/jquery.js"></script>
</head>

<body>
<ul>
  <li>list <strong>item 1</strong></li>
  <li><span>list item 2</span></li>
  <li>list item 3</li>
</ul>

<script>
$("ul").click(function(event) {
  var $target = $(event.target);
  if ( $target.is("li") ) {
    $target.css("background-color", "red");
  }
});
</script>

</body>
</html>

这里的$(event.target).is('li')是什么意思 为什么相当于 e.target.nodeName.toLowerCase()=='li'这个判断语句?

清风流光
浏览 2230回答 3
3回答

风筝_0010

is应该是jquery封装好的判断方式,首先event.target就是e.target,只是function里面的参数不一样,这个意思是目标节点,意思就是你点击的那个节点,e.target.nodeName是你点击的节点的名字,e.target.nodeName.toLowerCase()是把这个节点的名字变成小写,因为html里面也可以大写的LI,所以这个只是为了统一名称,e.target.nodeName.toLowerCase()=='li'就是判断你点击的节点是不是li节点。$(event.target)是把你点击的节点变成一个jquery对象,因为用$可以把DOM节点变成jquery对象,is是jquery提供的一个方法,用来判断节点类型的,$(event.target).is('li')就是判断点击的节点是不是li节点,和上面那个意思一样,只是这个是jquery实现的,上面那个是原生实现的

慕瓜9220888

SGXUTJQXOUJSHSSFMBSKZCXOTUKUCHOWUNULCTYQCIERXGHLQIHEOXQOQVEEBLJVPYETDOICAPYQZGTKKTUZBAJSZSEYDVNXISYWQGVAEHAGBCENVYWMGKWVQVOYEUXYNINGTKERZPXZCSVEOPUFBNXQKPKIUZSLEEFNPXZCBRVKTVNMMVYCMKMBJFJFCWKQBKKXAWPDZWHAKTQULXMNHGDWXHQVGABBHBCXSEONATXBXCNNQVFITYZFLERRYDWIHEPDEOSKVUNPSRWLGIKDCJVKSADCFOVWKHDSANWZCRCECEUUGGKLTJIBUUORPCRNTZSMESNFPILBOZQRZSVENAEFEMOEAHLNEQONNWCWABTIAGDPSULFEPPSSOQAFLJTFZSTODETWWSIVNFGFPKGGAXWYWPJMFEBDYUNXSFPWENVVBRNIPZIGTCCPPDOJIOYZJOFATUBXDQXH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