JQuery context menu

I am using Chris Domigan's jQuery context menu plugin to add a context menu. Here is how I do it:

$('#contacts tbody tr').contextMenu('myMenu1', {
    bindings: {
        'copy': function(t) {
             alert('Trigger was '+t.id+'\nAction was Copy');
         },

        'delete': function(t) {
             alert('Trigger was '+t.id+'\nAction was Delete');
        }
    },             
});

My question is: how do I get the contents of an item with the button pressed? I tried using

$(t.target).html()

but returns null. Any idea?

EDIT: here is an example http://jsfiddle.net/gqhRV/

+3
source share
2 answers

not familiar with the plugin, but from his views you can write:

$("#" + t.id).html();

but with most jQuery plugins you have to do this:

$(this).html();

out of context 'copy': function(t) {and'delete': function(t) {


$('#contacts tbody tr').contextMenu('myMenu1', {
    bindings: {
        'open': function(t) { ShowAction(t, "Open"); },
        'email': function(t) { ShowAction(t, "Email"); },
        'save': function(t) { ShowAction(t, "Save"); },
        'delete': function(t) { ShowAction(t, "Delete"); }
    }
});

function ShowAction(t, a) {
    alert('Trigger was ' + t.id + '\nAction was ' + a + "\nHtml is " + $(t).html());
}

Here is a working example: http://jsfiddle.net/dNUgg/

I assume tags <tr>do not have an attributeid


<tr> , : http://jsfiddle.net/dNUgg/1/


 alert('content is ' + $(t).text() + '\nAction was Delete');

jsfiddle: http://jsfiddle.net/gqhRV/1/

$(t.target).text(), $(t).text()

+7

, , :

<script type="text/javascript"> 
$(function(){
$.contextMenu({
    selector: '.flexme1 tbody tr', 
    callback: function(key, options) {
        alert("Clicked on " + key + " on element " + options.$trigger.attr('id').substr(3));            
    },
    items: {
        "edit": {name: "Edit", icon: "edit"},
        "cut": {name: "Cut", icon: "cut"},
        "copy": {name: "Copy", icon: "copy"},
        "paste": {name: "Paste", icon: "paste"},
        "delete": {name: "Delete", icon: "delete"},
        "sep1": "---------",
        "quit": {name: "Quit", icon: "quit"}
    }
});

$('.flexme1 tbody tr').on('click', function(e){
    console.log('clicked', this);
})
});
</script>

Flexigrid... ...

, , .

+9

Source: https://habr.com/ru/post/1786171/


All Articles