search

Home  >  Q&A  >  body text

javascript - When two spans are clicked respectively, a ul list will appear. Click ul. Is the value of li assigned to the currently clicked span?

I wrote two spans
When clicked respectively, the ul list can appear, but when the ul li is clicked, the values ​​​​of the two spans are all attached.
When one of them changes The other one will also change accordingly. My original intention was to click on that one and ask God to solve it

某草草某草草2772 days ago919

reply all(1)I'll reply

  • 世界只因有你

    世界只因有你2017-06-07 09:26:55

    This is what your code looks like. If you want to achieve the effect you want, you need to create a variable in home and work, such as

    var isJiatin = true;    //我们默认是家庭
    $('.jiatin').on('click', function(){
        isJiatin = true;
        $('.shequ ul li').show();
    })
    $('.danwei').on('click', function(){
        isJiatin = false;
        $('.shequ ul li').show();
    })
    $('.shequ ul li').on('click', function(){
        //先判断是家庭还是社区
        //do something 
    })
    

    Just the sauce

    reply
    0
  • Cancelreply