在表格行上打开新标签页,点击

问题描述:

if (/view/.test(self.location.href)) {
    $('.table tbody tr ').click(function() {
        var href = $(this).find("a").attr("href");
        if (href) {
            window.open(href, '_blank');
        }
    })
    $('.table tr').find('td:first').on('click', function(e) {
        // e.preventDefault();
        e.stopPropagation();
    });
}

在表行后单击浏览器,打开3个选项卡,哪里有问题?我只想打开1个标签.

After table row click browser open 3 tabs, where can be problem ? I want open only 1 tab.

尝试一下,您将了解您的问题:

try this and you will understand your issue:

alert($('.table tbody tr').length);

alert($('.table tbody tr ').length);

对不起,我没有收到您的问题.您必须这样做才能解决问题:

Sorry I didn't get your question. you have to do this to fix the issue:

if (/view/.test(self.location.href)) {
    $('.table tbody tr ').unbind('click');
    $('.table tbody tr ').click(function() {

解释(根据观众的要求)

基本上,可能是动态加载或多次加载的情况,因此它将绑定click操作,在这种情况下,将绑定3次,这将导致打开3个选项卡,使用unbind删除此先前的绑定,因此仅绑定事件一次.

Basically, it may be the case that you load it dynamically or many times, so it will bind the click action, in this case 3 times, which cause to open 3 tabs, using unbind delete this previous bind so it will only bind the event once.