【问题标题】:Script change/ way to stop executing script脚本更改/停止执行脚本的方式
【发布时间】:2011-09-24 12:44:49
【问题描述】:

我有以下表单示例:LIVE DEMO

它在 jNice 上运行(完整脚本):uncompressed versiuon

在我目前正在进行的项目中——我只需要它的部分功能——其他部分没有用。

通过将 'class="jNIce" 添加到表单元素来调用脚本。

我正在寻找:

  • 要么将其“起点”更改为 div 元素(不是表单)
  • 或在某些部分停止执行的方法

任何建议我可以从哪里开始?非常感谢任何帮助。

皮特

【问题讨论】:

    标签: jquery jquery-plugins jquery-selectors


    【解决方案1】:

    在查看了这个插件之后,我发现这个插件在它的源代码中有简单的解释。所以我测试了几分钟,找到了你问题的答案。

    首先,您想将其起点从<form> 更改为<div> 或其他内容。打开 jNIce 插件代码 (.js) 并滚动到文件末尾然后更改此行:

    /* Automatically apply to any forms with class jNice */ $(function(){$('form.jNice').jNice(); });

    到:

    /* Automatically apply to any forms with class jNice */ $(function(){$('div.jNice').jNice(); });

    在 html 的 body 中,只需删除 <div> 中的 class="jNice" 位置,该位置本身具有 form 元素(input,select,button,etc..)。插件会自动将它们更改为其样式。

    其次,你说你想阻止某些部分执行他们的更改。转到 jNice 插件中的第 27 行,您会看到:

    $('input:submit, input:reset, input:button', this).each(ButtonAdd); $('button').focus(function(){ $(this).addClass('jNiceFocus')}).blur(function(){ $(this).removeClass('jNiceFocus')}); $('input:text:visible, input:password', this).each(TextAdd); /* If this is safari we need to add an extra class */ if (safari){$('.jNiceInputWrapper').each(function(){$(this).addClass('jNiceSafari').find('input').css('width', $(this).width()+11);});} $('input:checkbox', this).each(CheckAdd); $('input:radio', this).each(RadioAdd); $('select', this).each(function(index){ SelectAdd(this, index); });

    如果您希望 jNice 停止更改您不喜欢的 form 元素,只需添加评论 \\ 或删除其行。比如我不要它的select框样式,我把评论放在:

    \\$('select', this).each(function(index){ SelectAdd(this, index); });

    希望你觉得这很有用:)

    【讨论】:

      【解决方案2】:

      找到了改变jNice脚本调用的方法:

      在最后一行之前我们有:

      $(function(){$('form.jNice').jNice();   });
      

      如果我们将其更改为 (form -> div(或任何我们想要的))

      $(function(){$('div.jNice').jNice();    });
      

      这样我们就可以在任何我们想要的(元素包装器或元素它自身)上调用 jNice。

      注册

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-07-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-01-01
        • 2010-10-07
        • 1970-01-01
        相关资源
        最近更新 更多