[英]jquery getting data from data-href
我試圖通過使用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://它現在可以正常工作。
饒有你的幫助!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.