【发布时间】:2017-02-14 11:31:52
【问题描述】:
我正在使用:jquery.dataTables.js 来自:https://datatables.net
我试图让每个 tr 都有一个链接,但由于某种原因这不起作用,我尝试在我的控制台上运行 chrome 并且工作正常,有人可以解释我为什么不能在我的元素中插入这个链接?
它与json数据有关吗?
html:
<div class=" dashboard">
<div class="col-md-8 no-padding">
<div class="form-group col-md-4 no-padding">
<select class="form-control" id="sel1">
<option value="Filter by">Filter by country </option>
<option value="All">All</option>
<option value="China">China</option>
<option value="EUA">EUA</option>
<option value="Spain">Spain</option>
</select>
</div>
</div>
<br>
<br>
<table id="example" class="display" width="100%" cellspacing="0">
<thead>
<tr>
<th>First name</th>
<th>Place</th>
</tr>
</thead>
</table>
jquery:
$(document).ready(function() {
var dt = $('#example').dataTable();
dt.fnDestroy();
});
$(document).ready(function() {
var url = 'http://www.json-generator.com/api/json/get/crcCiZXZfm?indent=2';
var table = $('#example').DataTable({
ajax: url,
columns: [{
data: 'name'
}, {
data: 'place'
}]
});
$('#sel1').change(function() {
if (this.value === "All") {
table
.columns(1)
.search('')
.draw();
} else {
table
.columns(1)
.search(this.value)
.draw();
}
});
});
$(document).ready(function() {
$('#example tbody tr').attr('onclick', "document.location = 'edit.html'");
});
jquery 我要插入:
$('#example tbody tr').attr('onclick', "document.location = 'edit.html'");
jsfiddle 但不是上面的 jquery: http://jsfiddle.net/f7debwj2/
【问题讨论】:
标签: javascript jquery json datatables