jQuery实现下拉框默认选中
<form class="form-inline" method="post" action="/score_result/"> <input type="hidden" name="csrfmiddlewaretoken" value="UIbksfQRejaZFuAByesMRE9rtyGZgfJmUWRyONLqF121IqjkunGxnihnMAbvrOE3"> <div class="form-group"> <label for="exampleInputEmail2">选款批次:</label> <select name="selection_batch" id="selection_batch" class="form-control"> <option value="0814">0814</option> <option value="0808">0808</option> <option value="0810">0810</option> <option value="0811">0811</option> <option value="0807">0807</option> </select> </div> <div class="form-group"> <label for="exampleInputName2">类目:</label> <select name="category" id="category" class="form-control"> <option value="小脚裤">小脚裤</option> <option value="阔腿裤">阔腿裤</option> <option value="半身裙">半身裙</option> <option value="运动裤">运动裤</option> <option value="哈伦裤">哈伦裤</option> <option value="牛仔外套">牛仔外套</option> <option value="工装裤">工装裤</option> </select> </div> <button type="submit" class="btn btn-default">查询结果</button> </form>
<script> // 批次号默认选中 $('select#selection_batch').find('option').each( function () { if ($(this).val() == '{{ selection_batch_post }}') { $(this).attr("selected", "selected"); } } ) </script>