判断点击li标签增加背景色为红色,如果点击的是第2个strong,当前的li增加背景色为绿色,

    xiaoxiao2021-12-10  7

    <ul> <li><strong>list</strong>item 1 - one strong tag</li> <li><strong>list</strong>item<strong>2</strong>- two <span>strong tags</span></li> <li>list item 3</li> <li><strong>sd</strong><strong>df</strong></li> </ul> js代码: $("li").click(function(){ var $li = $(this), isWithTwo = $li.is(function(){ return $('strong' , this).length === 2; }); if(isWithTwo){ $li.css("background-color" , "green"); } else{ $li.css("background-color","#0000FF"); } });
    转载请注明原文地址: https://ju.6miu.com/read-700348.html

    最新回复(0)