0

I have many hyper-links in a table tr so i want it to open whenever I refresh/load this page.

How do I do this? I checked in <a href there is no OnLoad option for calling any javascript function. please help me..

I have table like:

<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>
4

2 回答 2

2

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/

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

于 2013-09-13T14:17:39.683 回答
0

你能检查一下这个代码演示吗

$(document).ready(function(){
  $( "table tr a" ).each(function( index ) {
 window.open(this.href);
});
});
于 2013-09-13T14:17:10.797 回答