代码之家  ›  专栏  ›  技术社区  ›  Alex

jQuery-对元素激发函数

  •  1
  • Alex  · 技术社区  · 14 年前

    我在用

    $(".element").colorPicker(){ ... }
    

    这很管用。 问题是页面有一个AJAX表单,在提交时,它将用一个新表单(新的输入字段等)覆盖以前的表单。之后,颜色选择器停止工作。

    3 回复  |  直到 14 年前
        1
  •  1
  •   meder omuraliev    14 年前

    只需在ajax回调中重新附加调用,因为我认为没有可靠的事件可以用来 .live .delegate 但没有透露更多信息。

        2
  •  0
  •   Cristian Sanchez    14 年前

    $(".element").live('click focus', function () {
        var $this = $(this);
        if (!$this.data('hasColorPicker')) {
            $this.colorPicker({ /* ... */ }).data('hasColorPicker', true);
            $this.click(); // trigger the color picker - assuming it binds itself to the click event
        }
    });
    
        3
  •  0
  •   mkoistinen    14 年前

    meder所说的是好的,但是,如果您是通过复制现有的元素来创建新元素,请考虑使用 $.clone(true)