passing parameter to javascript onclick function

前端 未结 3 735
刺人心
刺人心 2021-01-28 18:40

I am having problem with getting parameter from javascript onClick function

title = \"as\"
$(\'
  • 3条回答
    •  [愿得一人]
      2021-01-28 19:13

      Please don't use inline js (onlick in your html).

      See reasons not to use inline js here: https://www.google.com/search?q=Why+is+inline+js+bad%3F

      Here's a proper way with jQuery:

      var $myElem = $('
    • '); $myElem.click(function() { pushRight('hello'); });

      And it's quite easy even without jQuery:

      var myElem = document.createElement('li');
      myElem.className = 'item';
      myElem.addEventListener('click', function() {
        pushRight('hello');
      });
      

      Live demo here: http://jsbin.com/uDURojOY/1/edit

    提交回复
    热议问题