這個為什么選擇出現問題? 就是last為什么選擇的不是我想要的 明明是有三個button卻選擇第二個為last
<body>
? ? <h2>hide</h2>
? ? <div class="left">
? ? ? ? <h4>測試一</h4>
? ? ? ? <div id="a1">hide操作</div>
? ? ? ? <button>直接hide</button>
? ? ? ? <script type="text/javascript">
? ? ? ? //點擊buttom1 直接隱藏
? ? ? ? $("button:first").click(function() {
? ? ? ? ? ? $("#a1").hide();
? ? ? ? });
? ? ? ? </script>
? ? ? ? <h4>測試一</h4>
? ? ? ? <div id="a2">hide動畫操作</div>
? ? ? ? <button>hide帶動畫</button>
? ? ? ? <script type="text/javascript">
? ? ? ? //點擊buttom2 執行動畫隱藏
? ? ? ? /*$("button:last").click(function() {
? ? ? ? ? ? $("#a2").hide({
? ? ? ? ? ? ? ? duration: 3000,
? ? ? ? ? ? ? ? complete: function() {
? ? ? ? ? ? ? ? ? ? alert('執行3000ms動畫完畢')
? ? ? ? ? ? ? ? }
? ? ? ? ? ? })
? ? ? ? });
? ? ? ? */
? ? ? ? $("button:last").css("color","red");
? ? ? ? </script>
? ? ? ? <h4>測試2</h4>
? ? ? ? <div id="a3">測試動畫</div>
? ? ? ? <button>點擊測試</button>
? ? ? ? <script type="text/javascript">
? ? ? ? ? ? $("button:eq(2)").click(function(){
? ? ? ? ? ? ? ? $("#a3").hide("slow");
? ? ? ? ? ? })
? ? ? ? ? $("button:last").css("color","blue");?
? ? ? ? ? ?$("button:first").css("color","green");
? ? ? ? </script>
? ? ? ??
? ? ? ??
? ? ? ??
</div>
? ? ? ??
</body>
</html>
2017-10-21
是的?;蛘叩?個腳本這樣寫,等全部文檔加載完再執行js代碼。
2018-10-07
?$("button:eq(2)").click(function(){? ?這句好像是選的第三個button 吧? eq(index)? index 從0 開始
2017-10-21
看你都學js這么長時間了,照理這點你應該早就知道了啊
2017-10-21
你干嘛一個例子寫一個<script></script>呢?直接統一在后面寫一個就夠了。
你這個腳本插入時,前面只有2個button,所以第二個button相對這個腳本來說就是最后一個button。
html文檔是由上往下執行的。