【问题标题】:Open two links when click on 'a'单击“a”时打开两个链接
【发布时间】:2018-04-03 05:48:01
【问题描述】:

我有如下 DOM:

<body>
<table>
<tbody>
<tr></tr>
</tbody>
</table>
<input type="text" class="pi" value=""><br>
<input type="text" class="vi" value="">
<button>users</button>
</body>

当用户点击按钮时,它会将新的“td”附加到“tr”。它运作良好。 问题: 在“a”点击时,我想打开两个链接。最好的方法是首先将当前页面重定向到另一个页面,然后打开单独的窗口。我试图更改另一个标签上的“a”,但没有帮助。

$('button').click(function () {
var pic = $('input[type="text"].pi').val();
var vid = $('input[type="text"].vi').val();
var cont = '<td><a data-big-image="' + vid + '" href="#"><img src="' + pic + '"></a></td>'
$('table').children('tbody').children('tr').last().append(cont);
});


$('a').click(function(e) {
e.preventDefault();
var bigImage = $(this).data('big-image');
window.open(bigImage);
window.open('xyz');
});

【问题讨论】:

标签: javascript jquery html


【解决方案1】:
  1. 像平常一样创建链接
  2. 接下来在链接中放置一个内联元素(例如&lt;b&gt;&lt;span&gt; 等)
  3. 然后为新元素添加一个内联属性事件处理程序。

    <a href="https://google.com" target="_blank">
      <b onclick="location.href='1st_location.html">GO</b>
    </a>
    

演示

(由于 SO 的安全措施无法正常工作,请参阅 PLUNKER

 <a href="https://google.com" target="_blank">
<b onclick="location.href='https://example.com';">GO</b></a>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-06-17
    • 2011-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多