javascript - Bootstrap-star-rating 插件 - 事件被多次调用
问题描述
我正在使用这个带有 JQuery 3.1.1 的Bootstap 星级插件版本 v4.0.5。我在调用 livequery 插件(来自作者Brandon Aaron)之后初始化了插件,因为我的星级输入是在 DOM 已经初始化时按需添加的。整个事情都很好,唯一的例外是事件被调用了这么多次。当用户与之交互时,它们在同一元素上被触发的次数不断增加。
请问,这可能是什么原因?有什么修复吗?
我的脚本:
$('.langLevel').livequery(function() {
$('#langLevel0').rating({
step: 1,
min: 0,
max: 5,
size: 'sm',
theme: 'krajee-fa',
// clearButton: '',
captionElement: "",
showCaptionAsTitle: false,
starCaptions: {
1: 'Beginner',
2: 'Intermediate',
3: 'Advanced',
4: 'Proficient',
5: 'Native'
},
starCaptionClasses: {
1: 'text-danger',
2: 'text-warning',
3: 'text-info',
4: 'text-primary',
5: 'text-success'
}
}).on("rating:clear", function(event) {
console.info("Your rating is reset");
}).on("rating:change", function(event, value, caption) {
console.info("You rated: " + value + " = " + $(caption).text());
});
}, function() {
// unmatchFn
return;
});
预先感谢您的帮助
解决方案
推荐阅读
- c# - 为什么应用程序需要一些 nuget 包引用?
- ruby-on-rails - 如何在AMS上的括号内渲染json一些没有括号的变量
- three.js - 将几何体拟合在一起
- c# - 解决 nuget 包引用
- java - can't seem to get Reegex to match
- json - Find common keys in JSON objects using jq
- javascript - Lit-Element : Outputting Raw HTML from Property String
- php - 需要正则表达式模式从日志文件中提取 xml 请求和响应
- sorbet - 控制器和助手
- angular - 角材料自动完成内的 ngTemplateOutlet 仅使用默认选项呈现