2017-02-19 4 views
0

私はB4で 'テーブルホバー'を使用していますが、実際にクリック可能になるようにホバリングされているテーブルの行にhrefを設定していますか?ブートストラップ4-テーブル行をクリック可能にする方法はありますか?

<table class="table table-hover"> 
    <thead> 
    <tr> 
     <th>#</th> 
     <th>First Name</th> 
     <th>Last Name</th> 
     <th>Username</th> 
    </tr> 
    </thead> 
    <tbody> 
    <tr> 
     <th scope="row">1</th> 
     <td>Mark</td> 
     <td>Otto</td> 
     <td>@mdo</td> 
    </tr> 
    <tr> 
     <th scope="row">2</th> 
     <td>Jacob</td> 
     <td>Thornton</td> 
     <td>@fat</td> 
    </tr> 
    <tr> 
     <th scope="row">3</th> 
     <td colspan="2">Larry the Bird</td> 
     <td>@twitter</td> 
    </tr> 
    </tbody> 
</table> 
+0

http://stackoverflow.com/questions/17147821/how-to-make-a-whole-row-in-a-table-clickable-as-a-link –

+0

どのような理由でクリック可能ですか?ナビゲートする、またはコンテンツを表示/非表示する – ZimSystem

答えて

1

これは1つの方法です。ここではJavascriptを使用していますが、window.location.assign( 'http://www.google.com')を使用しています。 "href"と同じことをします。ダブルクォートではなく、一重引用符に注意してください。

function hello(text) { 
 
alert(text); 
 
}
.table-hover tr:hover { 
 
background:#00ff00; 
 
}
<table class="table table-hover"> 
 
    <thead> 
 
    <tr> 
 
     <th>#</th> 
 
     <th>First Name</th> 
 
     <th>Last Name</th> 
 
     <th>Username</th> 
 
    </tr> 
 
    </thead> 
 
    <tbody> 
 
    <tr onclick="hello('row 1')"> 
 
     <th scope="row">1</th> 
 
     <td>Mark</td> 
 
     <td>Otto</td> 
 
     <td>@mdo</td> 
 
    </tr> 
 
    <tr onclick="window.location.assign('http://www.google.com');"> 
 
     <th scope="row">2</th> 
 
     <td>Jacob</td> 
 
     <td>Thornton</td> 
 
     <td>@fat</td> 
 
    </tr> 
 
    <tr onclick="hello('row 3')"> 
 
     <th scope="row">3</th> 
 
     <td colspan="2">Larry the Bird</td> 
 
     <td>@twitter</td> 
 
    </tr> 
 
    </tbody> 
 
</table>

関連する問題