嗨,我的应用程序中有多个具有相同结构的元素。第二个div元素的ID因数据库中唯一的注释ID而异。有些元素的ID为“vote_up”和“vote_down”。每个评论都会重复此操作。发生的事情是,正如我提到的,有多个评论。我想执行一个Ajax请求。首先,此结构使用ajax可以正常运行,而其余的则执行http请求。顺便说一句,我正在开发一个Rails应用程序,我正在使用jQuery。

<div id="post_comment">
john<i> says </i> Comment<br/>

<div id="comment_10_div">
**<form action="/comments/vote_up" id="vote_up" method="post">**
         <div style="margin:0;padding:0;display:inline">
               <input name="authenticity_token" type="hidden"
               value="w873BgYHLxQmadUalzMRUC+1ql4AtP3U7f78dT8x9ho=" />
         </div>
     <input id="Comment_place_id" name="Comment[post_id]" type="hidden" value="3" />
     <input id="Comment_id" name="Comment[id]" type="hidden" value="10" />
     <input id="Comment_user_id" name="Comment[user_id]" type="hidden" value="2" />
     <input name="commit" type="submit" value="Vote up" />
</form>

<label id="comment_10">10</label>

**<form action="/comments/vote_down" id="vote_down" method="post">**
        <div style="margin:0;padding:0;display:inline">
            <input name="authenticity_token" type="hidden"
            value="w873BgYHLxQmadUalzMRUC+1ql4AtP3U7f78dT8x9ho=" />
        </div>
    <input id="Comment_place_id" name="Comment[place_id]" type="hidden" value="3" />

    <input id="Comment_id" name="Comment[id]" type="hidden" value="10" />
    <input id="Comment_user_id" name="Comment[user_id]" type="hidden" value="2" />
    <input name="commit" type="submit" value="Vote Down" />
</form>
</div>

你能帮我解决这个问题吗
谢谢

最佳答案

是的,正如上面的Matti所述,按照W3C标准,ID必须是唯一的。一个不错的解决方法是在后缀注释的数据库ID后面加上例如<input id="Comment_39127438"...

09-25 18:41
查看更多