gpt4 book ai didi

javascript - jquery 从 data-href 获取数据

转载 作者:搜寻专家 更新时间:2023-10-31 22:55:42 25 4
gpt4 key购买 nike

我正在尝试使用 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';它正在运行,所以我知道曾经问题是......

我错过了什么?

编辑:柱塞: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:// 它现在可以工作了。

感谢您的帮助!

关于javascript - jquery 从 data-href 获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42751951/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com