Event handlers for Twitter Bootstrap dropdowns?

前端 未结 7 2092
不思量自难忘°
不思量自难忘° 2020-12-14 04:59

I\'d like to use a Twitter Bootstrap dropdown button:

    
7条回答
  •  没有蜡笔的小新
    2020-12-14 05:49

    I have been looking at this. On populating the drop down anchors, I have given them a class and data attributes, so when needing to do an action you can do:

  • Fred
  • and then in the jQuery doing something like:

    $('.dropDownListItem').click(function(e) {
        var name = e.currentTarget;
        console.log(name.getAttribute("data-name"));
    });
    

    So if you have dynamically generated list items in your dropdown and need to use the data that isn't just the text value of the item, you can use the data attributes when creating the dropdown listitem and then just give each item with the class the event, rather than referring to the id's of each item and generating a click event.

提交回复
热议问题