我将 token_input 用于自动完成功能。直到现在只有一个项目使用这个自动完成,所以我有这个脚本:
$(function() {
$("#bcl_tag_ids").tokenInput("/admin/tags/filter", {
crossDomain: false,
prePopulate: $("#bcl_tag_ids").data("pre"),
theme: "facebook"
});
});
现在会有很多,所以我带来了这样的东西:
$(function() {
$(".token_input").tokenInput("/admin/tags/filter", {
crossDomain: false,
prePopulate: $(".token_input").data("pre"),
theme: "facebook"
});
});
我现在不是在寻找一个 id,而是在寻找一个类,但我不知道如何修复路径 /admin/tags/filter
以便它可以动态加载正确的路径,例如 /admin/tags/filter
, /admin/musics/filter
, /admin/anythings/filter
.
我可以从 item#id
获取那部分路径,但我不知道该怎么做。
最佳答案
首先,将路径作为自定义属性添加到您的元素中
<input class="token_input" data-path="/admin/tags/filter"/>
然后,你可以做类似的事情
$(function() {
$(".token_input").each(function(){
$(this).tokenInput($(this).attr('data-path'), {
crossDomain: false,
prePopulate: $(this).data("pre"),
theme: "facebook"
});
});
关于许多项目的 Javascript/jquery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29757814/