EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: Aod47 on November 21, 2023, 11:00:45 PM



Title: Could you please advice how to add contextmenu when right click on textbox
Post by: Aod47 on November 21, 2023, 11:00:45 PM
I try the code below

Code:
<input class="easyui-textbox" id="textbox1">

<div id="mm" class="easyui-menu" style="width:120px;">
    <div data-options="iconCls:'icon-copy'">Copy</div>
    <div data-options="iconCls:'icon-cut'">Cut</div>
    <div class="menu-sep"></div>
    <div data-options="iconCls:'icon-paste'">Paste</div>           
</div>

$(document).ready(function (data) {
    $(document).bind('contextmenu', function (e) {
        var t = $(e.target).closest('.validatebox-text');
        if (!t.length) {
            e.preventDefault();
            $('#mm').menu('show', {
                left: e.pageX,
                top: e.pageY
            });
        } 
    });
});


When right click any position on display will show contextmenu 'mm'
but I want to show contextmenu when right click at textbox1 only.

Could you please advice? Many Thank.


Title: Re: Could you please advice how to add contextmenu when right click on textbox
Post by: Aod47 on November 22, 2023, 03:28:41 AM
Thank you every one. I got temporary solution  ;D by using tag span wrap textbox and bind context menu to span.

Code:
        $('#textbox1span').bind('contextmenu',function(e){
            e.preventDefault();
            $('#mm').menu('show', {
                left: e.pageX,
                top: e.pageY
            });
        });