如今Bootstrap這個前端框架已被許多人接受并應用在不同的項目中,其中“開發高效,設備兼容”的特點表現得非常明顯。再加上它默認的美觀的UI組件,簡直就是很多前端的大愛啊!!! 今天在這里跟大家分享Bootstrap table彈出右鍵菜單的實現方法。
最近遇到有一個需求,需要在Bootstrap table上使用右鍵。網上搜了半天沒有找到,最后發現Bootstrap table不支持右鍵(官方文檔給出的答案 https://github.com/wenzhixin/bootstrap-table/issues/241 )。
本文介紹使用contextMenu插件實現Bootstrap table右鍵功能。
代碼(test.html):
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><link rel="stylesheet" href="libs/bootstrap-table-v1.11.0/bootstrap.min.css" rel="external nofollow" ><link rel="stylesheet" href="libs/bootstrap-table-v1.11.0/bootstrap-table.css" rel="external nofollow" ><link href="libs/jQuery-contextMenu/dist/jquery.contextMenu.css" rel="external nofollow" rel="stylesheet"/><script src="libs/jQuery/jquery-1.8.3.min.js"></script><script src="libs/bootstrap-table-v1.11.0/bootstrap.min.js"></script><script src="libs/bootstrap-table-v1.11.0/bootstrap-table.js"></script><script src="libs/bootstrap-table-v1.11.0/bootstrap-table-zh-CN.js"></script><script src="libs/jQuery-contextMenu/dist/jquery.contextMenu.js"></script></head><body><table id="item_table"></table><script>$('#item_table').bootstrapTable({ columns: [{ field: 'id', title: 'Item ID' }, { field: 'name', title: 'Item Name' }, { field: 'price', title: 'Item Price' }], data: [{ id: 1, name: 'Item 1', price: '$1' }, { id: 2, name: 'Item 2', price: '$2' }]});$.contextMenu({ // define which elements trigger this menu selector: "#item_table td", // define the elements of the menu items: { foo: {name: "Foo", callback: function(key, opt){ alert("Foo!"); }}, bar: {name: "Bar", callback: function(key, opt){ alert("Bar!") }} } // there's more, have a look at the demos and docs...});</script></body></html>效果圖:

關于contextMenu的使用,可以參考網頁中右鍵功能的實現― contextMenu的使用 。
關于Bootstrap table的使用,可以參考官方文檔Bootstrap table。
以上所述是小編給大家介紹的使用contextMenu插件實現Bootstrap table彈出右鍵菜單,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對武林網網站的支持!
新聞熱點
疑難解答