2
Jquery正在rails視圖上使用。這裏的代碼示例:如何使HTML元素的id唯一,以便在Ajax響應的正確元素上添加某些內容
<div id="comments" class="comments">
<%= render :partial => 'comment', :collection => @comments %>
</div>
<script type="text/javascript">
$(function() {
$('#new_comment').bind('ajax:success', function(event, data, status, xhr) {
$('#comments').append('<div class="comment-item">' + data.text + '</div>');
});
});
</script>
我有一個表單發送ajax請求,並在響應JavaScript函數被調用。我在這個模式及其動態頁面中有多個位置。我需要使div的id唯一,並在正確的id中附加響應。我怎麼做?
如果你只是想要自己的類和id字符串,值得指出這些函數調用「dom_id」和「dom_class」。 – icecream 2010-12-18 00:53:21