使用contextMenu插件實(shí)現(xiàn)Bootstrap table彈出右鍵菜單
如今Bootstrap這個(gè)前端框架已被許多人接受并應(yīng)用在不同的項(xiàng)目中,其中“開(kāi)發(fā)高效,設(shè)備兼容”的特點(diǎn)表現(xiàn)得非常明顯。再加上它默認(rèn)的美觀的UI組件,簡(jiǎn)直就是很多前端的大愛(ài)?。。?! 今天在這里跟大家分享Bootstrap table彈出右鍵菜單的實(shí)現(xiàn)方法。
最近遇到有一個(gè)需求,需要在Bootstrap table上使用右鍵。網(wǎng)上搜了半天沒(méi)有找到,最后發(fā)現(xiàn)Bootstrap table不支持右鍵(官方文檔給出的答案 https://github.com/wenzhixin/bootstrap-table/issues/241 )。
本文介紹使用contextMenu插件實(shí)現(xiàn)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>
效果圖:

關(guān)于contextMenu的使用,可以參考網(wǎng)頁(yè)中右鍵功能的實(shí)現(xiàn)— contextMenu的使用 。
關(guān)于Bootstrap table的使用,可以參考官方文檔Bootstrap table。
以上所述是小編給大家介紹的使用contextMenu插件實(shí)現(xiàn)Bootstrap table彈出右鍵菜單,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
相關(guān)文章
showModalDialog 和 showModelessDialog
showModalDialog 和 showModelessDialog...2007-01-01
JS實(shí)現(xiàn)線性表的鏈?zhǔn)奖硎痉椒ㄊ纠窘?jīng)典數(shù)據(jù)結(jié)構(gòu)】
這篇文章主要介紹了JS實(shí)現(xiàn)線性表的鏈?zhǔn)奖硎痉椒?簡(jiǎn)單講解了線性表鏈?zhǔn)奖硎镜脑聿⒔Y(jié)合實(shí)例形式分析了js針對(duì)線性表鏈?zhǔn)奖硎镜膭?chuàng)建、插入、刪除等節(jié)點(diǎn)操作技巧,需要的朋友可以參考下2017-04-04
JavaScript焦點(diǎn)事件、鼠標(biāo)事件和滾輪事件使用詳解
這篇文章主要介紹了JavaScript焦點(diǎn)事件、鼠標(biāo)事件和滾輪事件使用詳解,通過(guò)示例給大家講解的非常細(xì)致,有需要的小伙伴可以參考下。2016-01-01
淺談bootstrap使用中的一些問(wèn)題以及解決過(guò)程
下面小編就為大家?guī)?lái)一篇淺談bootstrap使用中的一些問(wèn)題以及解決過(guò)程。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-10-10
JavaScript復(fù)制變量三種方法實(shí)例詳解
這篇文章主要介紹了JavaScript復(fù)制變量三種方法實(shí)例詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-01-01
深入理解JavaScript系列(3) 全面解析Module模式
Module模式是JavaScript編程中一個(gè)非常通用的模式,一般情況下,大家都知道基本用法,本文嘗試著給大家更多該模式的高級(jí)使用方式2012-01-01
dedecms頁(yè)面如何獲取會(huì)員狀態(tài)的實(shí)例代碼
下面小編就為大家?guī)?lái)一篇dedecms頁(yè)面如何獲取會(huì)員狀態(tài)的實(shí)例代碼。一起跟隨小編過(guò)來(lái)看看吧,希望對(duì)大家有所幫助。2016-03-03

