【问题标题】:How do I add a destroy method in jQuery CoolInput?如何在 jQuery CoolInput 中添加销毁方法?
【发布时间】:2010-04-19 13:52:19
【问题描述】:

我正在查看:CoolInput,但我需要一个销毁方法。

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

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

但我还需要一个类似的方法:

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

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

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

谢谢!

【问题讨论】:

    标签: jquery destroy


    【解决方案1】:

    你试过了吗

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

    ?

    【讨论】:

    • 有道理!为什么我没想到? >_
    • 很高兴它成功了。有时你只是盯着某样东西,却完全错过了显而易见的东西。我相信他们称之为“只见树木不见森林”。我从个人经验中知道这一点。
    【解决方案2】:

    稍微探索一下 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) { }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-24
      • 2019-03-04
      • 1970-01-01
      • 2019-01-26
      • 1970-01-01
      • 2011-04-07
      • 1970-01-01
      • 2015-03-10
      相关资源
      最近更新 更多