可能重複:
jQuery id selector works only for the first elementjQuery的不選擇所有
我希望jQuery選擇使用id =箱的所有div:
<!DOCTYPE html>
<head>
<link rel="stylesheet" href="css/main.css" type="text/css"/>
<script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
<script src="js/sizer.js"></script>
<title>
Design tests
</title>
</head>
<body>
<div id="box" style="width:300px;">
Hallo
</div>
<div id="box" style="width:300px;">
Hallo
</div>
<script>
$(document).ready(function(){
$("#box").mouseenter(function(){ $(this).css("border", "1px gray outset");}).mouseleave(function(){ $(this).css("border", "none");});
});
</script>
</body>
</html>
但它只選擇第一個。有人能幫幫我嗎?這不難嗎?
它的人有一個刺是什麼。免費代表! – andrewk
爲什麼所有的downvotes?僅僅因爲一個基本問題並不意味着它是不好的。 –
LoL,你不能有多個id。改爲使用類名稱。 '
'然後'$( 「箱子」)' – SpYk3HH