我在AngularJS中有一个复选框列表和一个提交按钮

时间:2016-10-06 12:07:33

标签: javascript html angularjs checkbox

如果选中最少的一个作业,我想启用取消按钮。

这是我的HTML视图

<table>
   <tr ng-repeat="x in jobs" ng-class-odd="'odd'" ng-class-even="'even'">
     <td style="width: 247px;">
        <input type="checkbox" ng-model="checked">
     </td>
     <td style="width: 247px;">{{ x.Name }}</td>
     <td style="width: 247px;">{{ x.Id }}</td>
   </tr>
</table>

<button ng-click="myFunc()" ng-disabled="countChecked()!=1">Cancel</button>

这是我的脚本

$scope.countChecked = function(){
   var count = 0;
   angular.forEach($scope.jobs, function(){
     if (checked) count++;
   });

   return count;
 }

我是AngularJS的新手。

2 个答案:

答案 0 :(得分:2)

checkjob集合的jobs内添加<table > <tr ng-repeat="x in jobs" ng-class-odd="'odd'" ng-class-even="'even'"> <td style="width: 247px; "> <input type="checkbox" ng-model="x.checked"> </td> <td style="width: 247px; ">{{ x.Name }}</td> <td style="width: 247px; ">{{ x.Id }}</td> </tr> </table> 属性。

checked

然后检查每个job

$scope.countChecked = function(){ var count = 0; angular.forEach($scope.jobs, function(job){ if (job.checked) count++; }); return count; } 属性,遍历每个集合项和增量计数
SELECT
    limid, COUNT(*), SUM(CASE WHEN cotavertical=MAX(cotavertical) THEN 1 ELSE 0 END), MAX(cotavertical)
FROM limites
LEFT JOIN tbparentchild ON parent=limid
LEFT JOIN tbspatialbi ON child=rgi
WHERE limtipo=4 AND x=1
GROUP BY limid

答案 1 :(得分:0)

您还可以将手表添加到集合中。

<!DOCTYPE html>

<html>
<head>
    <title>Atlas</title>
    <link rel="stylesheet" type="text/css" href="siteStyle.css">
    <link rel="shortcut icon" type="image/png" href="Logo.png" />
</head>
<body>
    <div class="website" style="background-color:black">
        <div class="menu">
            <ul>
                <li class="active"><a href="index.html">Home</a></li>
                <li><a href="bio.html">Biografie</a></li>
                <li><a href="projecten.html">Projecten</a></li>
                <li><a href="galerij.html">Galerij</a></li>
                <li><a href="contact.html">Contact</a></li>
            </ul>
        </div>
        <h2 style="color:white">Klik op de opties hier beneden</h2>
            <div class="homePage">
                <img src="grootLogo.png" class="mainFoto">
                <h4 style="position: absolute; top:50%;">Biografie</h4>
                <h5 style="position: absolute; top:50%;">Projecten</h5>
                <h4 style="position: absolute; top:75%;">Galerij</h4>
                <h5 style="position: absolute; top:75%;">Contact</h5>
                <br />
            </div>
    </div>
    <footer></footer>
</body>
</html>

我认为这是一个更具可读性,简洁和优雅的解决方案。有关详细信息,请查看here