1.需要网上下载的css和js jquery.contextMenu.css jquery.contextMenu.min.js
2.代码
/*右键菜单*/
$.contextMenu({
selector: "#tableId tbody tr", //给表格的行添加右键功能
items: {
good: {name: "好啊", callback: function(key, opt){
//key的值就是good
//$(this).find("#ttt").text()获取id为ttt<td>的值
alert(key+"---"+$(this).find("#ttt").text());
}
},
very good: {name: "非常好", callback: function(key, opt){ },
nice: {name: "优", callback: function(key, opt){
$.ajax({
method:'post',
data:'',
url:'xxxx',
success:function(result){
alert(result);
if(result!=null && result != undefined){
var str="";
var data=eval("("+result+")");
for(var i=0;i<data.length;i++){
str+="<option>"+data[i].id+"</option>"
}
$("#divId").html(str);
}
},
error:function(){
alert("terrible!")
}
});
}
},
perfect: {name: "完美", callback: function(key, opt){ alert(123);}}
}
});