繁体   English   中英

单击qtip jQuery中的按钮时获取上下文

[英]Get the context when clicking a button in a qtip jquery

这是一个普遍的问题。 我有下面的代码, #datatable是(你猜对了)一个datatable

$("#datatable").on(
    "mouseenter",
    "td",
    function(event) {
        $(this).qtip(
            {
                content:"<button>Test</button>",
                position: {
                    my: 'bottom left',
                    at: 'center right',
                    adjust : {
                        method: "shift"
                    },
                    viewport: $('#datatable')
                },
                show: {
                    event: event.type,
                    ready: true
                },
                hide: {
                    fixed: true
                }
            },
            event
        );
    }
);

当我单击qTip2工具提示中的按钮时,我希望能够使用$(this)所有优点(例如,获取列名和/或单元格的值)。

jsFiddle 在这里 :当您单击Test按钮时,如何显示带有列名的警报?

呈现工具提示后即可对其进行访问-Documentation Link

    events: {
        render: function(event, api) {
                // console.log( api ); // to see the full list
            console.log( api.target[0].innerText ); // return the text of the cell
        }
    }

小提琴

您可以为按钮提供一个类,并在呈现工具提示后单击触发。
不需要this关键字:

content:"<button class='my-btn'>Test</button>",
/*...*/
events: {
    render: function(e, api){
        $(".my-btn").on("click", function(){ 
            alert(api.target[0].innerText); 
        });
    }
}

现场演示

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM