我使用jquery插件“双面多选择”,如下所示:http://www.stevefenton.co.uk/cmsfiles/assets/File/twosidedmultiselect.html
使用常规rails帮助程序成功地显示一个常规多个选择框,代码如下:
<%= f.select(:expertise1, Tag.all.collect {|tag| [ tag.value, tag.value ] }, {}, {multiple: true, class: "multiselect"}) %>
我在资产中的javascripts文件夹中有jquery.twosidedmultiselector.js文件,并在页面源代码中看到它。Jquery必须在各处使用Jquery (rails 3.2.8)并在源代码中可见。(1.8.2)
但是,当我将它添加到javascript (在$(文档).ready(函数())中)时:
$(".multiselect").twosidedmultiselect();
我在javascript控制台中得到了这个错误,我完全不知道它意味着什么,也不知道如何修复它:
Uncaught TypeError: Object [object Object] has no method 'twosidedmultiselect'
救命!!非常感谢。
发布于 2012-10-31 13:24:42
将您的javascript封装在DOM就绪处理程序中,这将解决问题
$(function() {
// This is the only line you need for the plugin
$(".multiselect").twosidedmultiselect();
// The below script is for information / example...
// How to get the current selected items (note, they won't always have
// a "selected" attribute, but they will be in the box with the original ID:
var selectedOptions = $("#yourselect")[0].options;
});
在您的元素完全加载之前,您似乎使用了这些插件。在DOM处理程序中编写代码应该可以解决问题。
https://stackoverflow.com/questions/13167357
复制相似问题