我有一个html <table>显示日志,我想循环整个表突出显示<tr>具有不同值的行中的任何相邻单元格.
我试图比较<td>特定行中的任何两个值.我设法做了一些事情,但只有2列.
下面是表结构的html示例代码:
<table id="coa_history_data">
<tr>
<th>old Name</th>
<th>New Name</th>
<th>Old Phone</th>
<th>New Phone</th>
<th>Old Age</th>
<th>New Age</th>
</tr>
<tbody>
<tr class="data-in-table">
<td>Alphy</td>
<td>Alphy</td>
<td>015</td> //should be highlited
<td>016</td> //should be highlited
<td>23</td> //should be highlited
<td>24</td> //should be highlited
</tr>
<tr>
<td>Tom</td>
<td>Tom</td>
<td>12</td>
<td>12</td>
<td>65</td> //should be highlited
<td>30</td> //should be highlited
</tr>
<tr>
<td>will</td>
<td>will</td>
<td>45</td>
<td>45</td>
<td>20</td>
<td>20</td>
</tr>
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)
我的JavaScript代码:
$("#coa_history_data tbody tr.data-in-table").each(function() {
var $firstCell = $('td:eq(3)', …Run Code Online (Sandbox Code Playgroud) 我在这里做错了什么,我是棱角分明的新手,它显示上面的错误,这是我的代码
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.9/angular.js"></script>
<script>
function simpleController($scope){
$scope.customers=[
{name:'Alphy Poxy',city:'Mbita'},
{name:'Kibaki Watson',city:'Kikuyu'},
{name:'John Legend',city:'Lake'},
{name:'Sony',city:'HB'}
];
}
</script>
</head>
<body>
<div class="container-fluid" ng-controller="simpleController">
Name: <input type="text" ng-model="name"/>
<ul>
<li ng-repeat="coders in customers | filter:name | orderBy:'name'">{{coders.name}}-{{coders.city}}</li>
</ul>
</div>
</body>
Run Code Online (Sandbox Code Playgroud) 我用jquery动态生成了一个表数据.最初,当我用php完成它时,keyup事件工作得很好,我能够在T.Amount列中找到表的每一行的.qestimate和#number_of_houses的产品,但现在它不起作用,代码清单
HTML:
<table class="tg tg-table-light-1" border="">
<thead>
<tr>
<th>No.</th>
<th>Material</th>
<th>Qty</th>
<th>T. Amount</th>
</tr>
</thead>
</table>
Run Code Online (Sandbox Code Playgroud)
JQuery的:
$(document).ready(function() {
table=$('.tg-table-light-1');
$.getJSON("<?php echo base_url() . 'material_estimation/loadEstimates' ?>/", function(materialdetails) {
i=1;
$.each(materialdetails , function(i, materials){
newmaterials= materials.Materials;
sanitized_newmaterials=newmaterials.replace(/<\/?([a-z][a-z0-9]*)\b[^>]*>?/gi, '');
data="<tr class=\"tg-even\">
<td class=\"\">"+i+"</td>\n\
<td class=\"tg-even\">"+sanitized_newmaterials+"</td>\n\
<td class=\"\"><input type=\"text\" style=\"width:40px; text-align: center;\" class=\"qestimate\" name=\"qestimate[]\" value=\""+materials.Quantity_estimate+"\"/></td>\n\
<td class=\"\"><input type=\"text\" style=\"width:40px; text-align: center;\" class=\"tqty\" name=\"tqty[]\" value=\""+materials.total_quantity+"\"/></td>\n\
</tr>";
table.append(data);
i++;
});
});
Run Code Online (Sandbox Code Playgroud)
//触发事件
$(".tg-even input").keyup(multInputs);
Run Code Online (Sandbox Code Playgroud)
//我正在调用的函数但没有工作
function multInputs() {
var mult = 0;
$("tr.tg-even").each(function() {
// …Run Code Online (Sandbox Code Playgroud)