I\'m using Bootstrap and the following doesn\'t work:
Blah Blah
-
This code bellow will make your whole table clickable. Clicking the links in this example will show the link in an alert dialog instead of following the link.
The HTML:
Here's the HTML behind the above example:
Name
Description
Price
Edit
Apples
Blah blah blah blah
10.23
Edit
Bananas
Blah blah blah blah
11.45
Edit
Oranges
Blah blah blah blah
12.56
The CSS
And the CSS:
table#example {
border-collapse: collapse;
}
#example tr {
background-color: #eee;
border-top: 1px solid #fff;
}
#example tr:hover {
background-color: #ccc;
}
#example th {
background-color: #fff;
}
#example th, #example td {
padding: 3px 5px;
}
#example td:hover {
cursor: pointer;
}
The jQuery
And finally the jQuery which makes the magic happen:
$(document).ready(function() {
$('#example tr').click(function() {
var href = $(this).find("a").attr("href");
if(href) {
window.location = href;
}
});
});
What it does is when a row is clicked, a search is done for the href belonging to an anchor. If one is found, the window's location is set to that href.
- 热议问题