Javascript Can';不要在我的主项目中使用BootstrapSwitch()
我正在使用requirejs将我的javascript文件加载到项目中 正常情况下,我加载bootstrap_开关时考虑了它的所有已知依赖项,并且加载javascript时没有问题 例如,给定以下元素,要对其进行样式设置,我只需要执行$('my#el').bootstrapSwitch()Javascript Can';不要在我的主项目中使用BootstrapSwitch(),javascript,jquery,html,Javascript,Jquery,Html,我正在使用requirejs将我的javascript文件加载到项目中 正常情况下,我加载bootstrap_开关时考虑了它的所有已知依赖项,并且加载javascript时没有问题 例如,给定以下元素,要对其进行样式设置,我只需要执行$('my#el').bootstrapSwitch() 这一切都很好,因为元素已经创建。 当插件尝试向元素添加css类时,就会出现问题 应执行的所有代码都以字符串形式返回,如下所示: <div class="function () {
这一切都很好,因为元素已经创建。
当插件尝试向元素添加css类时,就会出现问题
应执行的所有代码都以字符串形式返回,如下所示:
<div class="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(" ");
}"><div><span class="bootstrap-switch-handle-on bootstrap-switch-primary">ON</span><label for="passage_valide"> </label><span class="bootstrap-switch-handle-off bootstrap-switch-default">OFF</span><input id="passage_valide" type="checkbox" data-size="small"></div></div>
开-关
但是,我尝试用我在项目中使用的相同Javascript文件创建一个原始JSFIDLE,它可以正常工作。
编辑
从BootstrapSwitch.js更改为代码的简化版本后,问题似乎是另一个
<div class="has-switch switch-animate switch-off" tabindex="0"><div><span class="switch-left">ON</span><label for="passage_valide"> </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"> </label><span class="switch-right">OFF</span><input id="passage_valide" type="checkbox" data-size="small"></div></div></div></div>
开-关-关
我也有同样的问题,我解决了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 };
-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 };