我希望从下拉列表中选择项目。我正在使用django表单来显示select2小部件。看起来像这样:
ToString();
HTML
rootcause = forms.MultipleChoiceField(choices=AuditedData.CHOICE_ROOTCAUSE,widget=Select2TagWidget( attrs={'data-placeholder': 'Search for root cause', 'data-width': '20em'}),label='')
<script type="text/javascript">
var selText;
$('.django-select2').on('change', function() {
selText ="";
$(".django-select2:selected").each(function () {
var $this = $(this);
if(selText !=""){
selText = selText.concat(",");
selText = selText.concat($this.text());
}
else
selText=$this.text();
});
document.getElementById("selected_values").value=selText;
});
</script>