javascript - if statement in change event in jquery fails
巴扎黑
巴扎黑 2017-05-19 10:10:24
0
2
594

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?

巴扎黑
巴扎黑

reply all (2)
大家讲道理

if($(this).val()==='1')

    刘奇

    0 and 1 are both strings, right? What you used is===, so...

      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!