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

如何在jquery coolinput中添加destroy方法?

  •  0
  • geffchang  · 技术社区  · 16 年前

    我在看: CoolInput 但我需要一种破坏方法。

    我希望能够做这样的事情:

    $('#manualhint2').coolinput('foobar');
    

    但我也需要一种方法,比如:

    $('#manualhint2').coolinput(destroy);  
    

    或者类似的,因为有时我需要禁用CoolInput。

    有人能帮我吗?
    或者,您也可以推荐另一个具有destroy方法的jquery提示库。

    谢谢!

    2 回复  |  直到 14 年前
        1
  •  2
  •   bobsoap    16 年前

    你试过了吗

    $('#manualhint2').coolinput(''); 
    

    ?

        2
  •  1
  •   Shahab    14 年前

    通过在CoolInput代码中进行一些探索,我得到了:

    $(selector).each(function () {
      EmptyThisCoolInput($(this));
    });
    
    function EmptyThisCoolInput(o) {
      try {
        if (o.val() == o.attr(coolInputAttribute) && o.hasClass(coolinputBlurClass))
          o.val("").removeClass(coolinputBlurClass);
      } catch (e) { }
    }
    

    我分开了 EmptyThisCoolInput 因为我在别的地方叫这个。您可以安全地使用此语法:

    $(selector).each(function () {
      try {
        if ($(this).val() == $(this).attr(coolInputAttribute) && $(this).hasClass(coolinputBlurClass))
          $(this).val("").removeClass(coolinputBlurClass);
      } catch (e) { }
    });
    
    推荐文章