Home  >  Q&A  >  body text

javascript - Use the on method to bind ui, the following li event, ui, li are generated by ajax, novice please help

Use on, but it cannot be bound, and I have doubts.

on method

/*选择车辆品牌*/
    $("#assessBrand").on('click',ul, function() {
        //想获取值,发现没绑定到,
        var tel =$(this).text();
         var rid =$(this).attr("tagnum");
         alert(tel);
         alert(rid);
         $("#taginput").attr("tagnum",rid);
        $("#taginput").attr("placeholder",tel);
        
    });

tag, since it is generated by ajax method without actual code, I used pictures

pThe following tags are all generated by ajax. I would like to ask how to bind events

漂亮男人漂亮男人2686 days ago624

reply all(3)I'll reply

  • 扔个三星炸死你

    扔个三星炸死你2017-06-12 09:21:56

    Did I write it wrong? Such as:

    $("#assessBrand").on('click', 'li', function() {
        // 略
    });

    Test: https://jsfiddle.net/4oyboawr/1/

    reply
    0
  • 高洛峰

    高洛峰2017-06-12 09:21:56

    Are you sure the on method is not written incorrectly? ? I don’t know how long I haven’t used jq, but my impression is that it is bound like this $(document).on(event, selector, callback)

    reply
    0
  • 三叔

    三叔2017-06-12 09:21:56

    Do you want to bind events to li below ul? You can use on directly

    reply
    0
  • Cancelreply