在更改类型和类别时,部门应该是change.it工作一次,但是当我更改类别并键入第二次而不刷新它不起作用。我不想第二次刷新页面或多更多时间。
<select id="CATEGORY_ID">
<option value="21">desc</option>
<option value="22">short</option>
<option value="23">medium</option>
<option value="24">long</option>
</select>
<select class="bx-user-field-enum" name="UF_TYPE">
<option value="1">comp</option>
<option value="2">query</option>
<option value="3">fault</option>
</select>
<select name=UF_DEPT>
<option value="21">Volvo</option>
<option value="22">Saab</option>
<option value="23">Mercedes</option>
<option value="24">Audi</option>
</select>
$('#CATEGORY_ID,[name=UF_TYPE]').on('change', function() {
var id = $('#CATEGORY_ID').val();
var select = $('.bx-user-field-enum').val();
if(id !=null && select !=null){
$.ajax({
type: "POST",
//dataType: 'json',
url:"ajax_dept.php",
data: {
select: select, id: id
},
success: function(msg) {
removeOptions(msg);
}
});
}
});
function removeOptions(msg) {
var cars = document.getElementsByName("UF_DEPT")[0];
var val = JSON.parse(msg);
for(var i=0; i<=cars.length; i++) {
var isFound = false;
for(var j=0;j<=i; j++) {
if(val[j] == cars[i].value) {
isFound=true;
//cars[i].style.color="red";
cars[i].style.display="block";
break;
}
}
if(!isFound) {
cars[i].style.display="none";
}
$('[name=UF_DEPT]').val(val[0]);
}
}