admin管理员组文章数量:1323738
I have a table where the first td in the trs contains a link. I want this anchor to be triggered (clicked) no matter where i click in the containing tr.
I have read and tried alot of recents post and suggentions on this topic but i can't get this to work. I tried the trigger() and triggerHandle() functions, but it does not trigger the anchor click that i want.
There must be others who have had the need to trigger a anchor click when a tr is clicked, so that the user doesn't have to click the tds anchor link. It sure is a nice UI feature if its possible?
Here is the code i have tried:
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="javascripts/jquery-1.4.2.js"></script>
<script type="text/javascript" charset="utf-8">
/* Initialise the table with the required column sorting data types */
jQuery(document).ready(function () {
jQuery("#rowClick tr").click(function (e) {
jQuery("#clickevent", this).trigger("click");
});
});
</script>
</head>
<body id="dt_example">
<table id="rowClick">
<thead>
<tr>
<th style="width: 30px">id</th>
<th style="width: 200px">navn</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="datatabletext.asp?test=1" id="clickevent">1</a></td>
<td>Jesper</td>
</tr>
<tr>
<td><a href="datatabletext.asp?test=2" id="clickevent">2</a></td>
<td>Bjarne</td>
</tr>
<tr>
<td><a href="datatabletext.asp?test=3" id="clickevent">3</a></td>
<td>Søren</td>
</tr>
</tbody>
</table>
</body>
I have a table where the first td in the trs contains a link. I want this anchor to be triggered (clicked) no matter where i click in the containing tr.
I have read and tried alot of recents post and suggentions on this topic but i can't get this to work. I tried the trigger() and triggerHandle() functions, but it does not trigger the anchor click that i want.
There must be others who have had the need to trigger a anchor click when a tr is clicked, so that the user doesn't have to click the tds anchor link. It sure is a nice UI feature if its possible?
Here is the code i have tried:
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="javascripts/jquery-1.4.2.js"></script>
<script type="text/javascript" charset="utf-8">
/* Initialise the table with the required column sorting data types */
jQuery(document).ready(function () {
jQuery("#rowClick tr").click(function (e) {
jQuery("#clickevent", this).trigger("click");
});
});
</script>
</head>
<body id="dt_example">
<table id="rowClick">
<thead>
<tr>
<th style="width: 30px">id</th>
<th style="width: 200px">navn</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="datatabletext.asp?test=1" id="clickevent">1</a></td>
<td>Jesper</td>
</tr>
<tr>
<td><a href="datatabletext.asp?test=2" id="clickevent">2</a></td>
<td>Bjarne</td>
</tr>
<tr>
<td><a href="datatabletext.asp?test=3" id="clickevent">3</a></td>
<td>Søren</td>
</tr>
</tbody>
</table>
</body>
Share
Improve this question
asked May 14, 2010 at 7:33
PokuPoku
3,18810 gold badges48 silver badges65 bronze badges
5 Answers
Reset to default 4Following on from naugtur and Alessandro; with the tds changed to have a class of 'clickevent':
$(document).ready(function () {
$("#rowClick tr").click(function (e) {
document.location.href = $(this).find(".clickevent").attr('href');
});
});
triggering clicks on a to reload the page is unavaliable due to security reasons.
try this way:
document.location.href=$aintd.attr('href');
$aintd is the a element You found
jQuery("#rowClick tr").click(function (e) {
jQuery(this).find('td:first a').click();
});
I should add that naugtur is correct in that this won't take you to another page, but anything that happens on the page itself will work fine.
Yeah, x1a4 is right. And remove the ids "clickevent" from your tds; the id attribute must be "a primary key" for a DOM element.
try the following
$("#rowClick tr").click(function (e) {
$(this).find('td:first a').trigger('click');
});
本文标签: javascriptJquery how to trigger td a when tr is clickedStack Overflow
版权声明:本文标题:javascript - Jquery: how to trigger td a when tr is clicked - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742120067a2421652.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论