<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("input").click(
function(){
alert(this.id);
$('#comments'+this.id).show();
}
);
});
</script>
<style type="text/css">
.comments{
width:500px;
height:350px;
background:#06F;
display:none;
}
</style>
</head>
<body>
<input type="text" id="1"></input>
<input type="text" class="title" id="2"></input>
<input type="text" class="title" id="1"></input>
<div id="comments1" class="comments">box 1</div>
<div id="comments2" class="comments">box 2</div>
<div id="comments1" class="comments">box 3</div>
</body>
最佳答案
元素ID
不能仅由数字组成
必须是唯一的
绝对没有办法解决这个问题。
您需要更改代码的结构以反映这一点。
如果需要匹配多个元素,请考虑使用类。