2014-09-04 3 views
0

테이블 행을 링크로 사용하려고합니다. 그래서 그것을하는 방법을 보여주는 몇 가지 답변을 찾았지만, 어떤 이유로 내 코드가 작동하지 않습니다. 아무도 그것이 작동하지 않는 원인을 찾도록 도와 줄 수 있습니까? 감사.테이블 행을 링크로 사용하기

지금까지 Making a table row (tr) clickable with jQuery (with an a href link, and hover!?)how to get selected table row values using jquery? 보고 노력했다.

<!doctype html> 
<html> 
    <head> 
     <meta charset="utf-8" /> 
     <title>X</title> 
     <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
     <style> 
     tr { 
      margin:2px; 
      padding:10px; 
      display:block; 
      background:#EEE; 
      cursor:pointer; 
     } 
     tr:hover { 
      background:#BBB; 
     } 
     </style> 
    </head> 
    <body> 


    <script> 

    $("tr").click(function() { 
     window.location.href = $(this).attr("href"); 
    }); 

    </script> 

<table class="tbl"> 
    <tr class=clickableRow href="http://www.zombo.com"> 
     <td>2014</td> 
     <td>ACADIA</td> 
     <td>SLE-2</td> 
    </tr><tr class=clickableRow href='http://www.xkcd.com'> 
     <td>2014</td> 
     <td>ACADIA</td> 
     <td>Denali</td> 
    </tr><tr class=clickableRow href='http://www.legit_url_not_fake_at_all.com'> 
     <td>2014</td> 
     <td>ACADIA</td> 

.... 
(SNIP) 

감사합니다.

답변

2

사용 Document.ready :

<script> 
    $(document).ready(function(){ 
     $("tr").click(function() { 
      window.location.href = $(this).attr("href"); 
     }); 
    }); 
</script> 
+0

감사합니다. 그게 효과가있어! – CarCzar

관련 문제