我正在使表格行可单击,但单击后我想打开一个新选项卡。我尝试使用data-target
但这没有用。
<tr class="table-row" data-href="mypage.php" data-target="_blank"></tr>
<script type="text/javascript">
$(document).ready(function ($) {
$(".table-row").click(function () {
window.document.location = $(this).data("href");
});
});
</script>
可以这样做:
jQuery: JSFiddle 1 https://jsfiddle.net/wxc80ybf/2/
$('.table-row').each(function() {
var $th = $(this);
$th.on('click', function() {
window.open($th.attr('data-href'), $th.attr('data-target'));
});
});
纯JS:JSFiddle 2 https://jsfiddle.net/wxc80ybf/3/
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'));
});
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)