我的form.py是: weight_training_days =表格.MultipleChoiceField(help_text = u'(必填)选择3天,widget = forms.SelectMultiple(attrs = {内联":是的,'class':'multiselect',}),选择=((0,星期一"),(1,周二"),(2,星期三"),(3,周四"),(4,星期五"),(5,星期六"),(6,太阳"),),) 我在模板中的表单是: < form class ="form-{{layout}}" action =" method ="post">{%csrf_token%}{{form | as_bootstrap:layout}}< p class ="form-actions">< input type ="submit" value =提交更改" class ="btn btn-primary"></p></form> bootstrap-multiselect.js文件(链接到静态文件夹中)中的js代码: $ {document).ready(function(){$('.multiselect').multiselect({buttonClass:"btn",buttonWidth:自动",buttonContainer:'< div class ="btn-group"/>',maxHeight:否,buttonText:函数(选项){如果(options.length == 0){返回未选择< b class ="caret"></b>";}否则,如果(options.length> 3){返回options.length +'selected< b class ="caret"></b>';}别的 {var selected ='';options.each(function(){选择+ = $(this).text()+',';});返回selected.substr(0,selected.length -2)+'< b class ="caret"></b>';}}});}); 由于某种原因,插件无法正常工作.仅显示一个标准的SelectMultiple字段.我在javascript方面的经验非常有限,并且不确定为什么该插件无法正常工作.任何反馈/帮助,我们将不胜感激.谢谢解决方案该问题是由于我对JavaScript缺乏经验/知识所致.我需要下载该插件的库,这就是bootstrap-multiselect.js文件中的内容.现在效果很好.I'm trying to create a multiselect dropdown menu witht the bootstrap-multiselect plugin in Django 1.4.5. Link to plugin: http://davidstutz.github.io/bootstrap-multiselect/My form.py is:weight_training_days = forms.MultipleChoiceField( help_text=u'(Required) Select 3 days', widget=forms.SelectMultiple(attrs={ 'inline': True, 'class': 'multiselect', }), choices=( (0, "Mon"), (1, "Tue"), (2, "Wed"), (3, "Thu"), (4, "Fri"), (5, "Sat"), (6, "Sun"), ),)My form in the template is:<form class="form-{{ layout }}" action="" method="post"> {% csrf_token %} {{ form|as_bootstrap:layout }} <p class="form-actions"> <input type="submit" value="Submit Changes" class="btn btn-primary"> </p></form>And the js code in the bootstrap-multiselect.js file (which is linked to in the static folder): $(document).ready(function() { $('.multiselect').multiselect({ buttonClass: 'btn', buttonWidth: 'auto', buttonContainer: '<div class="btn-group" />', maxHeight: false, buttonText: function(options) { if (options.length == 0) { return 'None selected <b class="caret"></b>'; } else if (options.length > 3) { return options.length + ' selected <b class="caret"></b>'; } else { var selected = ''; options.each(function() { selected += $(this).text() + ', '; }); return selected.substr(0, selected.length -2) + ' <b class="caret"></b>'; } } }); });For some reason the plugin is not working. Only a standard SelectMultiple field is presented.I have very limited experience with javascript and am not sure why this plugin won't work. Any feedback/assistance is greatly appreciated. Thanks 解决方案 The issue was due to my inexperience/knowledge of javascript. I need to download the library for this plugin and that is what went in the bootstrap-multiselect.js file. Works great now. 这篇关于在Django中,bootstrap-multiselect对Javascript是否正确?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 11-02 20:59