Get value of List Item with jQuery

后端 未结 5 974
后悔当初
后悔当初 2021-02-08 07:19

How to get value and index of list item onClick event with jQuery?
for example:

  • Item 1
  • Item 2&
5条回答
  •  我在风中等你
    2021-02-08 07:33

    If you had set a value attribute for your li:

        
    • Item 1
    • Item 2
    • Item 3
    • Item 4

    , then you can retrieve it using jQuery like this:

    $('#uItem li').click(function(){
        var $this = $(this);
        var selKeyVal = $this.attr("value");
        alert('Text ' + $this.text() + 'value ' + selKeyVal);
    })
    

提交回复
热议问题