【发布时间】:2015-10-05 19:23:09
【问题描述】:
我的视图中有一个基本的 DataTable。表格列之一显示电话号码。我必须处理的所有数字都是十位数,没有任何格式(如破折号或括号)。
我想用包含此电话号码的链接替换所有这些号码。
我该怎么做呢?
我根据这个问题尝试了一些方法: jquery, dynamically create link from text in td cell
我将代码替换为只有十位数的正则表达式。这是我在包含id="mydata" 的 HTML 表之后立即调用的脚本。该视图仅包含此表和脚本:
<script>
$(document).ready( function () {
$('#mydata').click(function(){
var phone = $(this).find(/\d{10}/).text();
window.location.href = "http://somelink" + phone + ".jpg"
});
$('#mydata').DataTable( {
deferRender: true, // Renders only the rows that are visible
dom: 'frtiS', // Additional parameters. See docs.
scrollCollapse: true, // Collapses table if there are few results
scrollY: 700 // Height of the container
} );
} );
</script>
不幸的是,无论我在表格中的哪个位置单击,这里的功能似乎都会触发,并且不会在链接中嵌入电话号码。
【问题讨论】:
标签: jquery ruby-on-rails datatables