这个插件可以帮我吗?
https://www.jqueryscript.net/form/Bootstrap-Combo-Box-Typeahead-Plugin-jQuery.html
我正在使用Bootstrap 3,并且已经将插件放在我的静态文件夹中。
我试图在我的选择字段中添加一个ID,但是没有用。
forms.py
class IndividuForm(forms.Form):
individu = forms.ModelChoiceField(queryset=Individu.objects.order_by('nom'), empty_label="")
def __init__(self, *args, **kwargs):
super(IndividuForm, self).__init__(*args, **kwargs)
self.fields['individu'].widget.attrs={'class': 'combobox','id':'mySelect'}
脚本
<script>
$('.mySelect').combobox()
</script>
答案 0 :(得分:0)
据我所见,您要定位的字段是:
<select class="combobox" id="mySelect"></select>
但是您的jQuery是针对性的
<select class="mySelect"></select>
, 要定位正确的元素,您应该使用:
$('#mySelect').combobox()
还要确保在页面上的组合框之前调用jQuery。
答案 1 :(得分:0)
对我来说,我以前从未听说过组合框,我可能会变老:)
但是您需要做的很简单。 只是在jquery中给变量一个函数
$('#select').on('change', function() {
alert( "Do whatever u want");
});