【问题标题】:adding jConfrim breaks function添加 jConfrim 中断功能
【发布时间】:2010-08-06 17:13:59
【问题描述】:

我正在尝试在此代码中添加一个确认框:

$('.widget .remove').live('click', function() { //Remove widget from layout
  $(this).closest('.widget').fadeOut('fast', function() {
    $(this).remove();
    saveLayout(false);
  });
  return false;
});

这就是我所做的:

$('.widget .remove').live('click', function() { //Remove widget from layout
jConfirm('Are you sure you want to remove this widget?','Are you sure?',function(r){
  if(r)
  {
      $(this).closest('.widget').fadeOut('fast', function() {
        $(this).remove();
        saveLayout(false);
      });
      return false;
  }
  });
});

在我开始使用它之前,删除功能效果很好,现在它什么都不做。我知道 if(r) 正在执行,因为我在测试时将测试警报(“消息”)放入了代码中。我对 jquery(或与此相关的 java 脚本)了解不足,无法知道出了什么问题。帮忙?

【问题讨论】:

  • 我对 jConfirm 不熟悉,但可能 $(this) 在处理程序内部不一样。尝试将 $(this) 替换为 $('.widget .remove')
  • 一个勇敢的努力,但没有奏效。

标签: asp.net jquery jquery-plugins


【解决方案1】:

main函数中的this与jConfirm中的this不同。

 var $this=$(this);

然后替换 jConfirm 中的每一个 (this) 解决了它

【讨论】:

    猜你喜欢
    • 2021-04-14
    • 1970-01-01
    • 2012-06-09
    • 2010-12-04
    • 1970-01-01
    • 1970-01-01
    • 2019-01-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多