為什么我用$("#arron:nth-child(1)").css("color","blue");就不能改變顏色
<!DOCTYPE html>
<html>
<head>
??? <meta http-equiv="Content-type" content="text/html; charset=utf-8" />
??? <title></title>
??? <style>
??? a {
??????
??????? font-size: 30px;
??????? font-weight: 900;
??? }
???
??? div {
??????? width: 200px;
??????? height: 100px;
??????? background-color: yellow;
??????? color: red;
??? }
??? </style>
??? <script src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script>
</head>
<body>
??? <h2>get方法</h2>
??? <div id="aaron">
??????? <a>1</a>
??????? <a>2</a>
??????? <a>3</a>
??????? <a>4</a>
??????? <a>5</a>
??? </div>
??? <select id="animation">
??????? <option value="1">get正數(shù)索引參數(shù)</option>
??????? <option value="2">get負(fù)數(shù)索引參數(shù)</option>
??? </select>
??? <input id="exec" type="button" value="點(diǎn)擊執(zhí)行">
??? <script type="text/javascript">
??? $("#exec").click(function() {
??????? $("#arron:nth-child(1)").css("color","blue");
??????? var v = $("#animation").val();
??????? var $aaron = $("#aaron a");
??????? //通過(guò)get找到第二個(gè)a元素,并修改藍(lán)色字體
??????? if (v == "1") {
???????????
??????? } else if (v == "2") {
??????????? //通過(guò)get找到最后一個(gè)a元素,并修改字體顏色
??????????? $aaron.get(-1).style.color = "#8A2BE2"
??????? }
??? });
??? </script>
</body>
</html>
2016-10-18
你的if 條件里都沒(méi)有寫,怎么執(zhí)行。這里給你注釋掉一行,那句不用寫,太麻煩了,而且書寫也不規(guī)范。
2018-10-11
$("#aaron>a:nth-child(2)").css("color","blue");
#aaron>a:nth-child(2)
選擇id為aaron元素的所有直接子元素中的a元素,如果其(a元素)是其父元素(div元素)的第二個(gè),則選中
2017-03-02
$("#aaron a:nth-child(2)").css("color","#FFF");
2016-11-29
沒(méi)看懂
2016-10-19
把你那代碼改成 $("div a:nth-child(1)").css("color","blue");就有用了??