jQuery live 功能不起作用

发布于 2024-09-27 17:36:22 字数 531 浏览 0 评论 0原文

除了我的 最后一个问题,我需要添加 .live() 功能,因为我动态添加内容

这就是我现在所拥有的

$('.PointsToggle').live('each',function() {
              $this = $(this);
              if ($this.text() == 'POINTS STATEMENT - AVAILABLE 7AM TOMORROW') {
                $this.width(510);
              } else {
                $this.width(20);
              }
            })

,但这现在似乎不起作用

有什么想法吗?

谢谢杰米

Further to my last question I need to add in the .live() function as i'm adding the content dynamically

This is what I have now

$('.PointsToggle').live('each',function() {
              $this = $(this);
              if ($this.text() == 'POINTS STATEMENT - AVAILABLE 7AM TOMORROW') {
                $this.width(510);
              } else {
                $this.width(20);
              }
            })

But this doesn't seem to work now

Any ideas?

Thanks

Jamie

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

忆离笙 2024-10-04 17:36:22

对于此类事情,您将需要 livequery 插件

$('.PointsToggle').livequery(function() {
  var $this = $(this);
  if ($this.text() == 'POINTS STATEMENT - AVAILABLE 7AM TOMORROW') {
    $this.width(510);
   } else {
    $this.width(20);
   }
})

For this sort of thing you will need the livequery plugin

$('.PointsToggle').livequery(function() {
  var $this = $(this);
  if ($this.text() == 'POINTS STATEMENT - AVAILABLE 7AM TOMORROW') {
    $this.width(510);
   } else {
    $this.width(20);
   }
})
↙厌世 2024-10-04 17:36:22

您只能使用.live()绑定事件处理程序,而“每个”不是。这应该有效:

$('.PointsToggle').live('load', function () { $(this).each(function () { ... }); });

You can only bind event handlers with .live(), which 'each' is not. This should work:

$('.PointsToggle').live('load', function () { $(this).each(function () { ... }); });
趁年轻赶紧闹 2024-10-04 17:36:22

我认为您可能想用“ var thisObject”替换“ $ this”:

$('.PointsToggle').live('each',function() {
          var thisObject = $(this);
          if (thisObject.text() == 'POINTS STATEMENT - AVAILABLE 7AM TOMORROW') {
            thisObject.width(510);
          } else {
            thisObject.width(20);
          }
        })

I think you probably want to replace '$this' with a 'var thisObject':

$('.PointsToggle').live('each',function() {
          var thisObject = $(this);
          if (thisObject.text() == 'POINTS STATEMENT - AVAILABLE 7AM TOMORROW') {
            thisObject.width(510);
          } else {
            thisObject.width(20);
          }
        })
何必那么矫情 2024-10-04 17:36:22

您可以在像单击这样的事件中使用每个方法,这意味着您可以在像本示例中这样的事件主体中使用此方法,

$("#Prefactor_save").live('click', function () {
    var tmp = "";
    alert(tmp);
    $("#factor_tb td").each(function () {
        tmp += $(this).val() + ",";
    });
    $("#factor_tb selected:option").each(function () {
        tmp += $(this).text() + ",";
    });
    alert(tmp);
}); 

我在单击事件中使用每个函数。

you can use each method in a event like click that mean which you can use this method in a body of a event like this

$("#Prefactor_save").live('click', function () {
    var tmp = "";
    alert(tmp);
    $("#factor_tb td").each(function () {
        tmp += $(this).val() + ",";
    });
    $("#factor_tb selected:option").each(function () {
        tmp += $(this).text() + ",";
    });
    alert(tmp);
}); 

in this sample I use each function in a click event.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文