[英]Grab Data from HTML table and put it into variable
我正在制作一个通过数据库自动填充的表,并使用angular循环遍历列表来填充html表。 我的问题是,我想这样点击一个单元格,它将打开一个新的网页,其中包含一个与该jobID相关的更具体的采石场。
不是我的问题是如何通过javascript从html表中获取值。 如果我可以点击我想要的单元格并将jobID放入var中,我想我可以做其他一切。
<div align=center>
<img src = "./img/heatmap.png"></img>
</div>
<div align=center>
Job ID:<input type="text" name="jobID" id="jobID"><br><br>
</div>
<div align=center>
<table id="Table" class="JobID-table" style="text-align:center" >
<tr class="table-Header">
<th>JOB ID</th>
<th>TIME FOR ALL MODULES(MILLISECONDS)</th>
</tr>
<tr class="jobID-Table-tr" ng-repeat="p in puller | orderBy : '-modCount'">
<td ng-click='someFunctionName(p.modName)'class={{p.cellClass}}>
{{p.modName}}
</td>
<td class={{p.cellClass}}>
{{p.modCount}}
</td>
</tr>
</table>
</div>
<script src = "js/vendor/angular.js"></script>
<script src = "js/app.js"></script>
<script src = "js/home-controller.js"></script>
这是控制器:
app.controller("homectrl", function($scope, $http){
$http.get("rest/performance").then(function(response){
$scope.puller = response.data;
for (var i = 0; i < $scope.puller.length; i++) {
var p = $scope.puller[i];
console.log("modName: " + p.modName);
console.log("modClass: " + p.cellClass);
console.log("modData: " + p.modCount);
}
$scope.someFunctionName(cellVal){
document.getElementById("jobID").value = cellval;
}
});
});
您可能想要探索ng-click
<td ng-click='someFunctionName(p.modName)'class={{p.cellClass}}>{{p.modName}}</td>
<td ng-click= class={{p.cellClass}}>{{p.modCount}}</td>
在控制器中
$scope.someFunctionName(cellVal){
// cellValue gives the content of the cell
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.