jQuery variable claiming it's undefined when it has been defined

后端 未结 4 2058
盖世英雄少女心
盖世英雄少女心 2021-01-27 17:40

I\'m trying to have two autofilling textboxes, one for a phone model - input1 and one for firmware - input2 on the same page. When both filled I want a div to be shown with the

4条回答
  •  不要未来只要你来
    2021-01-27 18:22

    The problem is the periods in your div's ID attributes and in your findFirmware() function, change it to

    function findFirmware(li) {
        if( li == null ) return alert("No match!");
        firmware = li.selectFirmware;
        firmwareid = phone.replace(".","");
        $(".info").hide();
        $('#' + phoneid + firmwareid).show(); // This line was messed up
    };
    

    There two problems with this line $(phoneid+firmware).show, well four if you count the missing parenthesis and semicolon but...

    1. The div your trying to show has an ID, you don't have # in your selector to select the element by ID
    2. firmware contains the unparsed string with the period so phoneid + firmware becomes iphone2g1.2 when your div ID is iphone2g12 thus you needed to use firmwareid in which you parsed it out of.

    Fiddle Demo: http://jsfiddle.net/AaNWM/

提交回复
热议问题