如何使用 data-href 新建选项卡
这样可以完成:
jQuery: JSFiddle 1
$('.table-row').each(function() { var $th = $(this); $th.on('click', function() { window.open($th.attr('data-href'), $th.attr('data-target')); }); });
Pure JS: JSFiddle 2
var tableRows = document.getElementsByClassName('table-row'); for (var i = 0, ln = tableRows.length; i < ln; i++) { tableRows[i].addEventListener('click', function() { window.open(this.getAttribute('data-href'), this.getAttribute('data-target')); }); }