【发布时间】:2017-03-31 07:54:05
【问题描述】:
我的表单如下所示:
<form action="/submit/" method="post" >{% csrf_token %}
<div class="col-lg-4 col-lg-offset-4">
<div class="form-group has-feedback">
<label class="control-label" for="inputSuccess2">Enter twitter username</label>
<input type="text" class="form-control" id="inputSuccess2", name='user'/>
<span class="glyphicon glyphicon-search form-control-feedback"></span>
<div class="text-center">
<label class="control-label" for="inputSuccess2">Select Job Type</label><br>
<select class="selectpicker" id="type" name="type"></select>
<br>
<div class="btn-group">
<select name="specialization" id="specialization"></select>
<br/></div>
<script language="javascript">
populateCountries("type", "specialization");
</script>
<br/>
<input class="btn btn-primary" type="submit" value="Submit">
</div>
</div>
</div>
</form>
下拉菜单的 js 文件如下所示:
var country_arr = new Array("Social Service and Education","Business and Sales","Language and Arts","Engineering and Technology", "Information Technology" );
// States
var s_a = new Array();
s_a[0] = "Please Select One";
s_a[1]="Counselor|School or Career Counselor|Community Service Manager|Social Worker|Preschool Teacher|Librarian|Professor|Psychologist";
s_a[2]="Sales Agent|Real Estate Agent|Accountant|Budget Analyst|Cost Estimator|Sales Engineer";
s_a[3]="Graphic Designer|Musician|Editor|Photographer|Translator|Artist";
s_a[4]="Chemical Engineer|Civil Engineer|Electronics Engineer|Environmental Engineer|Mechanical Engineer";
s_a[5]="Computer Programmer|Database Administrator|Software Developer|Web Developer";
function populateStates(countryElementId, stateElementId) {
var selectedCountryIndex = document.getElementById(countryElementId).selectedIndex;
var stateElement = document.getElementById(stateElementId);
stateElement.length = 0; // Fixed by Julian Woods
stateElement.options[0] = new Option('Select Specialization', '');
stateElement.selectedIndex = 0;
var state_arr = s_a[selectedCountryIndex].split("|");
for (var i = 0; i < state_arr.length; i++) {
stateElement.options[stateElement.length] = new Option(state_arr[i], state_arr[i]);
}
}
function populateCountries(countryElementId, stateElementId) {
// given the id of the <select> tag as function argument, it inserts <option> tags
var countryElement = document.getElementById(countryElementId);
countryElement.length = 0;
countryElement.options[0] = new Option('Select Job Type', '-1');
countryElement.selectedIndex = 0;
for (var i = 0; i < country_arr.length; i++) {
countryElement.options[countryElement.length] = new Option(country_arr[i], country_arr[i]);
}
$countryElementy.selectpicker('refresh');
// Assigned all countries. Now assign event listener for the states.
if (stateElementId) {
countryElement.onchange = function () {
populateStates(countryElementId, stateElementId);
};
}
}
但是,下拉菜单不起作用。如果我删除 selectpicker 类,我会失去样式。
有没有办法可以将引导样式与此代码一起使用?
【问题讨论】:
-
Bootstrap select 的样式为
.form-control,或者是您用来使其成为.dropdown的某个插件?
标签: css django twitter-bootstrap bootstrap-select