我正在尝试通过使用jQuery将表行作为链接,以下:
jQuery(document).ready(function() {
$(".clickable-row").click(function() {
window.location.href = $(this).data('href');
});
});
在我的html文件中,我有一个:
<tr class='clickable-row' data-href='my-page.com/user/123'>
<td><span class="glyphicon glyphicon-user"></span></td>
<td>{{ member.getFornamn }} {{ member.getEfternamn }}</td>
<td>{{ member.getEmail }}</td>
<td>{{ member.getTel1 }}</td>
<td>{{ member.getPostadress }}</td>
<td>{{ member.getPostnr }}</td>
</tr>
什么也没有发生。如果我更改此信息:window.location.href ='www.google.com';它正在工作,所以我知道是问题是...
我缺少什么?
编辑:plunker:http://plnkr.co/edit/0mbucaxr1fdpyzjzrlhc?p=preview
由于上述某些原因,对我不起作用。如果我使用它,则可以工作:
jQuery(document).ready(function() {
$(".clickable-row").click(function() {
window.location.href = '**any link at all**';
});
});
但是,当我更改此时,我的控制台日志甚至都不识别我的点击...?
jQuery(document).ready(function() {
$(".clickable-row").click(function() {
window.location.href = $(this).data('href');
});
});
我做到了:
jQuery(document).ready(function() {
$(".clickable-row").click(function() {
thisdata = $(this).attr('data-href');
console.log(thisdata);
window.location.href = thisdata;
});
});
和控制台给了我正确的答案。
我注意到我的实际桌子看起来像这样:
<tr class='clickable-row' data-href='URL://my-page.com/user/123
'>
因此,通过删除 url://现在起作用。
th和您提供帮助!