how to deal with multiple ids in query as i have problem in the following code
<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>
Element IDs
Must not consist of a number only
Must be unique
There is absolutely no way around this.
You need to change your code's structure to reflect that.
If you need to match multiple elements, consider using classes.
The best option when you have multiples that need action is to change the id to a class. IF you truly have DIFFERENT needs for the id, then you should consider some option that includes modification of the ID in that it CANNOT have duplicates and be valid.
And of course ID must begin with a non-numeric character.
EDIT: some detailed notes regarding naming rules:
- Must begin with a letter A-Z or a-z
- Can be followed by: letters (A-Za-z), digits (0-9), hyphens ("-"), underscores ("_"), colons (":"), and periods (".")
- Values are case-sensitive
精彩评论