Html 单击 td 空间时重定向到 url
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4182487/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
redirect to url on clicking in td space
提问by Ata
is there any way when to go to URL when user click in <td>
.
当用户单击时,有什么方法可以转到 URL <td>
。
回答by x2.
<td><a href="http://example.com"> </a></td>
or
或者
<td onclick="window.location='http://example.com'"></td>
回答by ace
Bind a Javascript method to the onclick event on the TD, if you are using jQuery you can do this:
将 Javascript 方法绑定到 TD 上的 onclick 事件,如果您使用的是 jQuery,则可以执行以下操作:
$(document).ready(function(){
$("td").click(function(){
// Perform your action on click here, like redirecting to a new url
window.location='http://google.com';
});
});
回答by ArK
for same window
对于同一个窗口
onclick="window.location('www.example.com')"
for new window
对于新窗口
onclick="window.open('www.example.com')";
回答by Ramiz Uddin
If you don't want to have any other element
in your td
then you can do it this way:
如果你不想有任何其他人element
,td
那么你可以这样做:
<td onclick="javascript:window.location.href-'http://www.stackoverflow.com'" style="cursor:hand">Stackoverflow</td>
回答by generalhenry
either fill the td with an <a>
or set it's onclick
to window.location = "URL"
要么用 td 填充 td<a>
要么将其设置onclick
为window.location = "URL"
回答by Zain Shaikh
You can do it like following:
你可以这样做:
$(document).ready(function(){
$('#myTd').click(function(){
window.location= "http://google.com";
});
});
demo here: http://jsfiddle.net/zainshaikh/4acMG/3/
回答by Damien
Some of these answers provide javascript. Please always include a normal (anchor tag) link for visitors who don't have javascript active in their browser.
其中一些答案提供了 javascript。请始终为浏览器中没有激活 javascript 的访问者提供一个普通(锚标记)链接。
回答by Ahsan Ahmed
There are three ways you can do so.
您可以通过三种方式执行此操作。
1) <td><a href="http://example.com">Click me</a></td>
1) <td><a href="http://example.com">Click me</a></td>
2) <a href="http://example.com"><td>Click me</td></a>
2) <a href="http://example.com"><td>Click me</td></a>
3) <td onclick="window.location='http://example.com'"></td>
3) <td onclick="window.location='http://example.com'"></td>