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[i].id+data.data[i].type_name+"("+color[num]+")"+''; } $("#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[i].id+data.data[i].type_name+"("+color[num]+")"+''; } $("#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?
if($(this).val()==='1')
0 and 1 are both strings, right? What you used is
===
, so...