视频里灭绝老师讲解checked的时候,操作checked需要加上parent()才会生效,但是加上parent会影响到其他含有子元素的标签,老师在视频中只是注释掉了受影响的标签,
并没有介绍如何才能只影响到被check的标签而不影响其他含有子元素的标签,
所以想知道,怎么才能操作check标签而不会影响其他标签,希望老师解答
<!doctype html>
<html>
<head>
<meta charset="gbk">
<title>选择器篇作业</title>
<script src="jquery-3.3.1.min.js"></script>
</head>
<style>
*{padding:0;margin:0}
</style>
<script>
$(document).ready(function(){
$('input[type][name=shouji]').css('background','pink');//属性选择器
$('div:contains(aaaa)').css('background','pink');//内容选择器
$('#bb ul li').css('list-style','none');//层级选择器
$('#bb ul li:odd').css('background','pink');//顺序选择器
$(":selected").css('background','pink');//表单选择器
$(":checked").parents().css('color','red');
})
</script>
<body>
<div>aaaa</div>
<div id="bb">
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ul>
</div>
<!--属性选择器-->
<form action="">
<lable>姓名<input type="xingming" name='xingming'></lable>
<lable>手机<input type="shouji" name='shouji'></lable>
<select name="city" id="city">
<option>武汉</option>
<option selected>黄石</option>
</select>
<input type="checkbox">11
<input type="checkbox">22
<input type="checkbox" checked>33
</form>
</body>
</html>