使用JS获取选中的复选框的值

本例子虽然使用的是AngularJS,其实用其他的框架、模板都是一个道理。

html:

<tr ng-repeat="project in dpList">
    <td class="text-center">{{$index + 1 + ((currentPage-1)*pageSize)}}</td>
    <td>{{project.fullName}}</td>
    <td>{{project.typeName}}</td>
    <td align="center">
        <input type="checkbox" name="proShortCodeArr" value="{{project.shortCode}}">
    </td>
</tr>

js:

$scope.relevance=function(){
    var obj=document.getElementsByName("proShortCodeArr")
    var checkValue=[];
    for(var i=0;i<obj.length;i++){
        if(obj[i].checked && obj[i].value!=null) checkValue.push(obj[i].value);
    }
};

checked 为true表示该复选框被选中。

原文地址:https://www.cnblogs.com/VitoYi/p/7737680.html