<p class="add-new-img mt-2">
<select name="picType" id="img-type">
<option value="0">彩色</option>
<option value="1">黑白</option>
</select>
</p>
<p class="add-new-img mt-2">
<select name="picType" id="img-type-classify">
</select>
</p>
Two drop-down boxes, give the first drop-down box a change event, request a different ajax address, and change the data of the second drop-down box
$("#img-type").change(function(){
console.log($(this).val())
if($(this).val()===1){
console.log(1)
$.ajax({
type : 'GET',
data: {
'type': '2',
"type_classify":1
},
url: "/Type/getTypeList",
dataType: "json",
success: function(data){
var color = ["彩色","黑白"]
var options='';
for(var i=0;i<data.data.length;i++){
var num = Number(data.data[i].type_classify)
options += '<option value='+data.data[i].id+'>'+data.data[i].id+data.data[i].type_name+"("+color[num]+")"+'</option>';
}
$("#img-type-classify").html(options);
},
error:function(msg){
console.log(msg);
},
});
}
if($(this).val()===0){
console.log(0)
$.ajax({
type : 'GET',
data: {
'type': '2',
"type_classify":0
},
url: "/Type/getTypeList",
dataType: "json",
success: function(data){
var color = ["彩色","黑白"]
var options='';
for(var i=0;i<data.data.length;i++){
var num = Number(data.data[i].type_classify)
options += '<option value='+data.data[i].id+'>'+data.data[i].id+data.data[i].type_name+"("+color[num]+")"+'</option>';
}
$("#img-type-classify").html(options);
},
error:function(msg){
console.log(msg);
},
});
}
})
Determine the value of the first drop-down box and request different background interfaces. But the console output $(this).val() is normal, but the console has no effect in the if statement. What is the reason?