2012-08-30 105 views
0

你好,我想使div的我有我的td的行为作为href的。我怎样才能做到这一点?HTML DIV的TD内部作为href的

也许与jQuery或JavaScript,如果不与HTML ?? ??

<table class="mgmtview_table" align="center"> 
    <tr> 
    <td class="content" id="content"> 
     <table class="content_table"> 
     <tr> 
     <td class="topBar"> 
     <div id="div_view" align="center">FusionCharts will load here!</div> 

    </td> 
     <td class="topBar"> 
     <div id="div_view2" align="center">FusionCharts will load here!</div> 
    </td> 
     <td class="topBar"> 
     <div id="div_view3" align="center">FusionCharts will load here!</div> 
    </td> 
    </tr> 

     <tr> 
     <td class="topBar"> 
     <div id="div_view4" align="center">FusionCharts will load here!</div> 
    </td> 
    <td class="topBar"> 
     <div id="div_view5" align="center">FusionCharts will load here!</div> 
    </td> 
    <td class="topBar"> 
     <div id="div_view6" align="center">FusionCharts will load here!</div> 
    </td> 
    </tr> 

     <tr> 
     <td class="topBar"> 
     <div id="div_view7" align="center">FusionCharts will load here!</div> 
    </td> 
    <td class="topBar"> 
     <div id="div_view8" align="center">FusionCharts will load here!</div> 
    </td> 
    <td class="topBar"> 
     <div id="div_view9" align="center">FusionCharts will load here!</div> 
    </td> 
    </tr> 

+4

为什么不只是使用标签? – manish

+0

我同意伊马尼亚语 - 你为什么要这么做? –

+1

确实。你可以将它们设置为'display:block'来使它们像一个块元素(就像一个div)一样,所以你可以像使用div一样给它赋予宽度,高度和其他属性。根本不需要Javascript。 – GolezTrol

回答

3

使用jQuery你可以做这样的事情:

$('table.content_table td div').click(function(){ 
    alert('clicked'); 
    location.href='http://google.com'; 
}); 

但是如果你想要的链接,那么你真的应该使用<a href="...">。这就是他们的目标。 :p

1

答案是你没有。

用html记住一条重要的规则就是使用正确的元素来完成你想要做的工作。这就是为什么存在这样一系列要素。

一个你开始搞乱交换元素,你打开一个蠕虫罐,不仅具有跨浏览器兼容性,而且具有可访问性。

使用HTML锚点元素。您可以使用任何您喜欢的方式对其进行设置,如果需要,可以使用JavaScript轻松覆盖默认行为。有关Anchor元素的更多信息,请查看here中包含的信息。