Datatables Find Replace If Statement
Datatables Find Replace If Statement
如何查找/替换数据表中的特定元素?我正在尝试用字体很棒的图标替换表中的元素:
JavaScript:
$(document).ready(function() {
$('#example').dataTable();
$('td').html().replace('0', '<i class="fa fa-thumbs-o-up"></i>');
$('td').html().replace('1', '<i class="fa fa-warning"></i>');
} );
J投标:http://jsfiddle.net/wo02xedr/
使用old
参数迭代文本并替换:
$('td').text(function (i, old) {
$(this).html(old.replace('0', '<i class="fa fa-thumbs-o-up"></i>').replace('1', '<i class="fa fa-warning"></i>'))
});
jsFiddle
您的一些代码是错误的,开始吧。。
$(document).ready(function() {
$('#example').dataTable();
$("td").each(function() {
$(this).html( $(this).html().replace('0', '<i class="fa fa-thumbs-o-up"></i>').replace('1', '<i class="fa fa-warning"></i>'));
});
});
这是jsFiddle链接http://jsfiddle.net/wo02xedr/2/
我看到了一些改进:
- 首先,应该使用
$("td").each(function() {...})
对每个元素进行循环 - 用以下内容更新
td
的html(此处仅阅读):$this.html(...)
这给出了这样的结果:
$('td').each(function () {
var $this = $(this);
$this.html($this.html()
.replace('0', '<i class="fa fa-thumbs-o-up"></i>')
.replace('1', '<i class="fa fa-warning"></i>'));
});
看看这把小提琴:http://jsfiddle.net/wo02xedr/8/
相关文章:
- Jquery else if statement
- Rails 3 if statement with jQuery?
- JQuery Else if statement?
- 在jQuery .load Ajax之后执行if-statement
- Javascript if statement if (ball.style.left === '0px'
- If-Statement中的Javascript元素验证
- Javascript document.cookie if statement
- Javascript Logic In a loop/if statement
- Javascript if statement Google Tools
- Javascript IF statement
- ActionScript 3 If/ Else If Statement
- Javascript if-statement vs. comparsion
- Javascript condense if statement
- 嵌套的 if's:使用 if (x) {statement;} 还是 if (!x) 返回更好;陈述;
- Javascript optimizing if statement
- Javascript and CSS if statement
- JQUERY, AJAX if else statement
- Vuejs IF statement
- Datatables Find Replace If Statement
- javascript msgbox if statement