gpt4 book ai didi

javascript - 如何在页面加载时从超链接打开 url

转载 作者:行者123 更新时间:2023-12-02 18:21:25 26 4
gpt4 key购买 nike

我在 table tr 中有很多超链接所以我希望它在我刷新/加载此页面时打开。

我该怎么做?我签到了<a href没有OnLoad调用任何 javascript 函数的选项。请帮助我..

我有这样的表格:

<table> 
<tr class="oddrow">
<td>Google</td>
<td>
<a style="color: blue;" href="www.google.com"> my website link 1</a>
</td>
</tr>

<tr class="oddrow">
<td>Stackoverflow</td>
<td>
<a style="color: blue;" href="www.stackoverflow.com"> my website link 2</a>
</td>
</tr>

<tr class="oddrow">
<td>Yahoo</td>
<td>
<a style="color: blue;" href="www.yahoo.com"> my website link 2</a>
</td>
</tr>
</table>

最佳答案

您在标签上提到了 jQuery,因此:

$(function () {
$("table tr td a").each(function (idx, el) {
// As your markup is invalid - href to an external page not
// starting with http://, let's add it here.
// Otherwise the browser will interpret it as an anchor.
var w = window.open("http://" + $(el).attr("href"));
});
});

演示:http://jsfiddle.net/kqLSY/3/

大多数浏览器都会阻止此行为,因为它试图打开弹出窗口。

关于javascript - 如何在页面加载时从超链接打开 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18788469/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com