onclick event pass
  • id or value
  • 前端 未结 4 1250
    悲哀的现实
    悲哀的现实 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:33

    • s don't have a value - only form inputs do. In fact, you're not supposed to even include the value attribute in the HTML for
    • s.

      You can rely on .innerHTML instead:

      getPaging(this.innerHTML)
      

      Or maybe the id:

      getPaging(this.id);
      

      However, it's easier (and better practice) to add the click handlers from JavaScript code, and not include them in the HTML. Seeing as you're already using jQuery, this can easily be done by changing your HTML to:

    • 1
    • 2
    • And use the following JavaScript:

      $(function () {
          $('.clickMe').click(function () {
              var str = $(this).text();
              $('#loading-content').load('dataSearch.php?' + str, hideLoader);
          });
      });
      

      This will add the same click handler to all your

    • s, without requiring you to duplicate your onclick="getPaging(this.value)" code for each of them.

    提交回复
    热议问题