在数组中签入时插入 td 标记值
Insert the td tag value when checked in array
我有一个表,其中包含某些类型的数据和复选框。我所需要的只是将表的数据插入数组中,仅在选中复选框的情况下。这是我的代码。
<table class="table table-bordered table-striped table-condensed flip-content" style="margin-top: 10em;">
<thead class="flip-content">
<tr>
<th class="hidden-print">Include</th>
<th style="text-align: center;">Quantity</th>
<th style="text-align: center;" class="hidden-print">Cost(USD)</th>
<th style="text-align: center;" class="hidden-print">Markup(%)</th>
<th style="text-align: center;" class="hidden-print">Markup Amount</th>
<th style="text-align: center;color: #f00;" class="hidden-print">Your Profit(<?php echo $_SESSION['level_markup']; ?>%)</th>
<th style="text-align: center;" class="hidden-print">Company Profit</th>
<th style="text-align: center;">Price(USD)</th>
<th style="text-align: center;">Price Per piece</th>
<th style="text-align: center;" class="hidden-print">Actions</th>
</tr>
</thead>
<tbody style="text-align: center;">
<?php
$x=0;
foreach($query_initial as $qurintl)
{
?>
<tr class="hidden-print">
<td class="hidden-print"><input type="checkbox" value="" name="" id="checkbox1"></td>
<td> {{ quantity = <?php echo $qurintl['business_quantity']; ?> }} </td>
<td class="hidden-print"><input ng-model="basecost_<?php echo $x; ?>" ng-init="basecost_<?php echo $x; ?>=<?php echo $qurintl['business_final_price']; ?>" type="text" </td>
<td class="hidden-print"><input ng-model="markup_<?php echo $x; ?>" ng-init="markup_<?php echo $x; ?>=<?php echo $_POST['markupper']; ?>"></td>
<td class="hidden-print"> ${{ marukpamount = (basecost_<?php echo $x; ?> * markup_<?php echo $x; ?>) / 100 | number:2 }}</td>
<td class="hidden-print" style="color: #f00;"> ${{ yourprofit = (marukpamount * <?php echo $_SESSION['level_markup']; ?>) / 100 | number:2 }}</td>
<td class="hidden-print"> ${{ marukpamount - yourprofit | number:2 }}</td>
<td> ${{ results = basecost_<?php echo $x; ?> -- (basecost_<?php echo $x; ?> * markup_<?php echo $x; ?>) / 100 | number:0 }}</td>
<td>${{ results / quantity | number:2 }}</td>
<td class="hidden-print"><input type="button" class="btn btn-danger" value="-"></td>
</tr>
<?php
$x++;
}
?>
</tbody>
</table>
你把角度和PHP混合在一起,这可能不是解决问题的最佳方法。您应该将所有$qurintl
添加到 javascript 数组中,然后按如下方式构建表:
var myApp = angular.module('myApp', []);
function MyCtrl($scope) {
$scope.all = [{
business_quantity: 3,
business_final_price: 2,
markupper: 5
}, {
business_quantity: 3,
business_final_price: 3,
markupper: 2
}, {
business_quantity: 3,
business_final_price: 5,
markupper: 4
}];
$scope.level_markup = 3;
$scope.selected = [];
$scope.actualize = function() {
$scope.selected = $scope.all.filter(function(data) {
return data.checked;
});
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.min.js"></script>
<body ng-app ng-controller="MyCtrl">
<table class="table table-bordered table-striped table-condensed flip-content" style="margin-top: 10em;">
<thead class="flip-content">
<tr>
<th class="hidden-print">Include</th>
<th style="text-align: center;">Quantity</th>
<th style="text-align: center;" class="hidden-print">Cost(USD)</th>
<th style="text-align: center;" class="hidden-print">Markup(%)</th>
<th style="text-align: center;" class="hidden-print">Markup Amount</th>
<th style="text-align: center;color: #f00;" class="hidden-print">Your Profit({{level_markup}}%)</th>
<th style="text-align: center;" class="hidden-print">Optamark's Profit</th>
<th style="text-align: center;">Price(USD)</th>
<th style="text-align: center;">Price Per piece</th>
<th style="text-align: center;" class="hidden-print">Actions</th>
</tr>
</thead>
<tbody style="text-align: center;">
<tr ng-repeat="data in all">
<td class="hidden-print">
<input ng-click="actualize();" ng-model="data.checked" type="checkbox">
</td>
<td>{{data.business_quantity}}</td>
<td class="hidden-print">
<input ng-model="data.business_final_price" type="text" />
</td>
<td class="hidden-print">
<input ng-model="data.markupper">
</td>
<td class="hidden-print">${{ markupamount = data.business_final_price * data.markupper / 100 | number:2 }}</td>
<td class="hidden-print" style="color: #f00;">${{ yourprofit = markupamount * level_markup / 100 | number:2 }}</td>
<td class="hidden-print">${{ marukpamount - yourprofit | number:2 }}</td>
<td>${{ results = data.business_final_price - (data.business_final_price * data.markupper) / 100 | number:0 }}</td>
<td>${{ results / data.business_quantity | number:2 }}</td>
<td class="hidden-print">
<input type="button" class="btn btn-danger" value="-">
</td>
</tr>
</tbody>
<div>Your Array: {{selected}}</div>
</table>
</body>
相关文章:
- 将样式表插入iframe
- Ckeditor-plugin:插入虚假元素add不情愿<p>标签前后
- 如何动态插入jquery代码
- 正在获取生成的PHP td值
- 动态插入的表:JQuery未检测到最后一行
- 使用JavaScript动态插入DIV的成本有多高
- 带有填充属性的SVG矩形显示在包含元素的上方插入框阴影
- 如何在td元素中添加监听器
- 将对象动态插入到现有对象中
- 将数组中的值插入到表中
- 在 Java 中的 JavaScript 函数中插入 Wicket 值
- 如何首先设置样式<td>表中包含在窗体中的元素
- 我如何在数字插入中使用逗号,这样它就不会'不要破坏我的输入字段
- 使用PHP插入HTML在JavaScript上不起作用
- javascript:将数据库中的数据插入到html5文本字段中
- 从数据库中获取数据并插入JavaScript变量
- 如何使用innerHtml正确插入html
- AngularJS指令,在元素后插入HTML
- Knockout.js和表:插入<th>将内容转换为匹配<td>
- 在数组中签入时插入 td 标记值