【发布时间】:2018-02-21 07:27:24
【问题描述】:
我使用 jquery 附加选项来选择 它的工作,但我想添加
<option value="0">choose category</option>
在任何选择之后 当我在 html 中添加它时,它在选择选项 apeend 后被隐藏
<script type="text/javascript">
$(document).ready(function() {
$('select[name="cat"]').on('change', function() {
$('select[name="subcat"]').removeClass('hidden');
$('select[name="subcat2"]').addClass('hidden');
//$('select[name="subcat2"]').find('option').remove().end();
var stateID = $(this).val();
if(stateID) {
$.ajax({
url: '{{ url('getCat') }}/'+stateID,
type: "GET",
dataType: "json",
success:function(data) {
$('select[name="subcat"]').empty();
$.each(data, function(key, value) {
$('select[name="subcat"]').append('<option value="'+ key +'">'+ value +'</option>');
});
}
});
}else{
$('select[name="subcat"]').empty();
}
});
});
【问题讨论】:
-
更清楚...