增加输入标记内的ID属性

时间:2015-08-19 08:19:28

标签: javascript jquery html

我在表格中有一个表格,其中每个字段都附有检查按钮。有三个级别 1)。选择所有信息 2)。亲 3)。子

我想要做的是,如果我选择“选择所有信息”复选按钮,它会选择所有正常工作的复选框。我无法做的是,如果我选中“父”复选框,它应该选中所有孩子的复选框。我试图增加Child_id字段,但没有得到任何富有成效的结果。

以下是我正在尝试的代码,任何帮助或指导都很有用

class Hello {
    static var className: String = ""


    init() {
        Hello.className = "hello"
    }

    class func someFunc() {
        println(self.className = "hello") 
    }
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js">
  </script>

<script>
  $(function select(){
	     $("#Select_All").change(function () {
          $("#Parent_Id, #Child_Id").prop("checked", this.checked);
           });
 
$("#Parent_Id").change(function(){ 
        var i=0;   
        $('#Child_Id').each(function(){
        i++;
        var newID='Child_Id'+i;
        $(this).attr('id', newID);
        $(this).val(i);
             $(newID).prop("checked", this.checked);
 });});});
	</script>

1 个答案:

答案 0 :(得分:1)

试试这个:

&#13;
&#13;
var myApp = angular.module('myApp',[]);

myApp.controller('myController', function($scope, $timeout) {

    $scope.myToggle = function() {
      // Check to see if there already is a $scope.loading timer
      if($scope.loading){
        // if there is then use the $timeout.cancel() method
        $timeout.cancel($scope.loading);
      }
      // Initialize the $timeout into the $scope.loading propert
      $scope.loading = $timeout(
        function() {
          $scope.loading = false;
      }, 3000);
    }
});
&#13;
&#13;
&#13;

由于您更改了每个子元素的ID,因此您选中/取消选中最顶层的父元素(Select_All),只有&#34; parent&#34;元素会受到影响,所以我会评论一些代码行以使其正常运行。

DEMO

相关问题