JQuery全選Prop(“check”,true)和attr("attr",true)區別


$scope.selectAll = false;
//點擊單選框的時候是不是全選
$scope.checkIsAll = function(){

    var wipeCheckBoxObj = $("input[name='wipeCheckBox']:checked");


    if(wipeCheckBoxObj.length==$scope.dataLists.length){
        //全選
        $scope.selectAll = true;
    }else{
        $scope.selectAll = false;
    }
}

//全選、取消全選
$scope.checkAllBox = function(selectAll){

    var wipeCheckBoxObj = $("input[name='wipeCheckBox']");

    if(selectAll){
         wipeCheckBoxObj.prop("checked",true);
        /**最好不要用下面這個,因為這樣會用問題!!!最開是的時候以為是jquery--1.6版本沒有attr屬性,只能用prop(),
    但是我換了高版本的jQuery有時候還是會出現問題,具體問題還不是很清楚,所以最好還是用prop這個屬性吧
*/ //wipeCheckBoxObj.attr("checked",true); }else{ wipeCheckBoxObj.attr("checked",false); } }

//刪除全部選中的數據
$scope.deleteAllSelectedDate = function(){
    var wipeCheckBoxObj = $("input[name='wipeCheckBox']:checked");

    if(!wipeCheckBoxObj||wipeCheckBoxObj.length==0){
        return ;
    }else{
        var finacialValue = "";
        //獲取選中數據的ID
        wipeCheckBoxObj.each(function(){
             finacialValue += ($(this).val()) + ",";
        });

        //去掉最后一個逗號
        finacialValue =finacialValue.substr(0,finacialValue.length-1);

        $http({
            url:'/ecp/financial/deleteAllSelectedWipeData',
            method:"DELETE",
            param:{
                "selectedWipeDatas":finacialValue
            }
        }).success(function(data){
            if(data=='true'){
                //刪除成功之后給提示,並刷新數據!!!
                var objDiv = "objDiv";
                startObjMessage(objDiv);
                $scope.getAllAddedWipeoutData();
            }
        }).error(function(data){
            console.log("operateWipeoutCtrl批量刪除數據失敗!!!!");
        });
    }
}
 
         

 






<table class="table table-hover">
    <thead>
    <tr>
        <th class="col-md-1" style="text-align: center">
            <!--這里用ng-change比用ng-click要好!!!!!!!!!!ng-click觸發了可能selectAll的值還沒變,但是ng-change一定是selectAll的值改變了才會執行!!!!!!!-->
            <input type="checkbox" ng-model="selectAll" ng-change="checkAllBox(selectAll)">全選</th>
        <th class="col-md-1" style="text-align: center">單&nbsp;&nbsp;號</th>
        <th class="col-md-1" style="text-align: center">報&nbsp;銷&nbsp;人</th>
        <th class="col-md-2" style="text-align: center">類目(用途)</th>
        <th class="col-md-2" style="text-align: center">項&nbsp;&nbsp;目</th>
        <th class="col-md-2" style="text-align: center">金&nbsp;&nbsp;額(元)</th>
        <!--<th class="col-md-1" style="text-align: center">類&nbsp;&nbsp;型</th>-->
        <th class="col-md-1" style="text-align: center">時&nbsp;&nbsp;間</th>
        <th class="col-md-2" style="text-align: center">操&nbsp;&nbsp;作</th>
    </tr>
    </thead>
    <tbody>
    <tr ng-model="topics" ng-repeat="item in dataLists">
        <td class="col-md-1" style="text-align: center"><input type="checkbox"  ng-click="checkIsAll()" value="{{item.id}}" name="wipeCheckBox"></td>
        <td class="col-md-1" style="text-align: center"><span class="mr-badge red-bg">{{item.orderNumber}}</span></td>
        <td class="col-md-1" style="text-align: center"><span>{{item.reimbursement}}</span></td>
        <td class="col-md-2" style="text-align: center"><span title="{{item.category}}">{{item.category}}</span></td>
        <td class="col-md-2" style="text-align: center"><span ng-bind="item.project"></span></td>
        <td class="col-md-2" style="text-align: center"><span ng-bind="item.money"></span></td>
        <!--<td class="col-md-1" style="text-align: center"><span ng-bind="item.type"></span></td>-->
        <td class="col-md-1" style="text-align: center"><span ng-bind="item.createdOn"></span></td>
        <td class="col-md-2" style="text-align: center"><button class="btn btn-danger btn-xs" ng-click="deleteData(item.id,'objDiv')">刪除</button>
            | <button class="btn btn-success btn-xs"  ng-click="openPop(item)">編輯</button></td>
    </tr>
    <tr ng-if="dataLists.length==0||dataLists==''">
        <td class="col-md-2">暫無數據</td>
    </tr>

    </tbody>
</table>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM