onclick event pass
  • id or value
  • 前端 未结 4 1248
    悲哀的现实
    悲哀的现实 2021-02-05 06:20

    I want to pass

  • id or value in onclick event. here is my exiting code.

  • 4条回答
    •  遥遥无期
      2021-02-05 06:47

      I prefer to use the HTML5 data API, check this documentation:

      • https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes
      • https://api.jquery.com/data/

      A example

      $('#some-list li').click(function() {
        var textLoaded = 'Loading element with id='
               + $(this).data('id');
         $('#loading-content').text(textLoaded);
      });
      
      
      • One
      • Two
      • Other

    提交回复
    热议问题