不能将BootstrapSwitch()用于我的主项目

时间:2014-02-26 11:34:13

标签: javascript jquery html

我正在使用requirejs将我的javascript文件加载到项目中。

正常情况下,我正在加载bootstrap_switch,考虑到所有已知的依赖项,并且正在加载javascript而没有问题。

例如,给定以下元素,为了设置它,我只需要做$('#my_el')。bootstrapSwitch()

<input id="my_el" type="checkbox" data-size="small">

自元素创建以来,这一切都很好。 当插件尝试将css类添加到元素时,会出现此问题。

应该执行的所有代码都以字符串形式返回,如下所示:

<div class="function () {
              var classes;
              classes = [&quot;&quot; + _this.name];
              classes.push(_this.options.state ? &quot;&quot; + _this.name + &quot;-on&quot; : &quot;&quot; + _this.name + &quot;-off&quot;);
              if (_this.options.size != null) {
                classes.push(&quot;&quot; + _this.name + &quot;-&quot; + _this.options.size);
              }
              if (_this.options.animate) {
                classes.push(&quot;&quot; + _this.name + &quot;-animate&quot;);
              }
              if (_this.options.disabled) {
                classes.push(&quot;&quot; + _this.name + &quot;-disabled&quot;);
              }
              if (_this.options.readonly) {
                classes.push(&quot;&quot; + _this.name + &quot;-readonly&quot;);
              }
              if (_this.$element.attr(&quot;id&quot;)) {
                classes.push(&quot;&quot; + _this.name + &quot;-id-&quot; + (_this.$element.attr(&quot;id&quot;)));
              }
              return classes.join(&quot; &quot;);
            }"><div><span class="bootstrap-switch-handle-on bootstrap-switch-primary">ON</span><label for="passage_valide">&nbsp;</label><span class="bootstrap-switch-handle-off bootstrap-switch-default">OFF</span><input id="passage_valide" type="checkbox" data-size="small"></div></div>

但是,我尝试使用我在项目中使用的相同Javascript文件创建一个原始jsfiddle并且它可以工作。 http://goo.gl/Mco5rR

修改

从BootstrapSwitch.js更改为代码的缩小版本后,问题似乎是其他问题。

<div class="has-switch switch-animate switch-off" tabindex="0"><div><span class="switch-left">ON</span><label for="passage_valide">&nbsp;</label><span class="switch-right">OFF</span><div class="has-switch switch-animate switch-off" tabindex="0"><div><span class="switch-left">ON</span><label for="passage_valide">&nbsp;</label><span class="switch-right">OFF</span><input id="passage_valide" type="checkbox" data-size="small"></div></div></div></div>

1 个答案:

答案 0 :(得分:0)

我有同样的问题,我解决了在bootstrap-switch.js暂时删除第75行和第95行的问题

    -75  return function() {
var classes;
              classes = ["" + _this.name];
              classes.push(_this.options.state ? "" + _this.name + "-on" : "" + _this.name + "-off");
              if (_this.options.size != null) {
                classes.push("" + _this.name + "-" + _this.options.size);
              }
              if (_this.options.animate) {
                classes.push("" + _this.name + "-animate");
              }
              if (_this.options.disabled) {
                classes.push("" + _this.name + "-disabled");
              }
              if (_this.options.readonly) {
                classes.push("" + _this.name + "-readonly");
              }
              if (_this.$element.attr("id")) {
                classes.push("" + _this.name + "-id-" + (_this.$element.attr("id")));
              }
              return classes.join(" ");
    -95 };