可能重复:
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