【发布时间】:2012-08-21 13:15:59
【问题描述】:
当用户点击删除时,我曾经能够使用下面的代码隐藏一行,为什么它停止工作了
$(document).ready(function () {
$('.deleteRecord').live( function() {
if(confirm("Are you sure?")){
$(this).closest('tr').fadeOut();
}
});
});
哈姆线
\#{link_to image_tag('/img/icons/packs/diagona/16x16/101.png', :border => 0), schedule, :method => :delete, :remote=>true, :class=>'deleteRecord'}
这是我的 application.js 中的内容,所有其他事件似乎都在工作或触发,减去这个
//= require jquery
//= require rails
//= require jquery_ujs
//= require jquery-ui
//= require best_in_place
//= require plugins
//= require messages
//= require_self
$(document).ready(function() {
jQuery(".best_in_place").best_in_place();
$('.best_in_place').bind("ajax:success", function(){
$(this).closest('tr').effect("pulsate", { times:3 }, 500);
});
});
$(window).load(function () {
$('#tab-panel-1').createTabs();
$('#dataTable').dataTable(
{
"aLengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
"aaSorting": [[ 4, "desc" ]]
}
);
});
$(document).ready(function () {
$('.deleteRecord').on('click', function() {
if(confirm("Are you sure?")){
$(this).closest('tr').fadeOut();
}
});
$('#notice').effect("pulsate", { times:3 }, 500);
});
【问题讨论】:
-
除了您的问题之外,请确保您确实需要 .live() 它还将为未来的元素绑定,并且应该仅在您在绑定后编辑表格时使用。否则使用 .on()
-
jQuery 官方文档 从 jQuery 1.7 开始,.live() 方法已被弃用。使用 .on() 附加事件处理程序。旧版本 jQuery 的用户应该使用 .delegate() 而不是 .live()。 link
-
记录是在文档加载之后还是之前添加的?
标签: jquery ruby-on-rails haml