Use Bootstrap 3 dropdown menu as context menu

后端 未结 4 870
不思量自难忘°
不思量自难忘° 2020-11-29 16:12

Using Bootstrap 3, how can I place the dropdown menu at the cursor and open it from code?

I need to use it on a table as a context menu for its rows.

4条回答
  •  庸人自扰
    2020-11-29 17:05

    Added some modifications to KyleMit's code:

    • moved "on document click" handler from "foreach"
    • removed "foreach", just add event to selector
    • hide menu on "document context menu"
    • passing events

      $("#myTable tbody td").contextMenu({
      menuSelector: "#contextMenu",
      menuSelected: function (invokedOn, selectedMenu) {
          var msg = "You selected the menu item '" + selectedMenu.text() +
              "' on the value '" + invokedOn.text() + "'";
          alert(msg);
      },
      onMenuShow: function(invokedOn) {
          var tr = invokedOn.closest("tr");
          $(tr).addClass("warning");
      },
      onMenuHide: function(invokedOn) {
          var tr = invokedOn.closest("tr");
          $(tr).removeClass("warning");
      } });
      

    http://jsfiddle.net/dmitry_far/cgqft4k3/

提交回复
热议问题