📜  在 AngularJS 中获取复选框状态的 ng-checked 的替代方法

📅  最后修改于: 2021-10-29 03:43:34             🧑  作者: Mango

任务是在 AngularJS 的帮助下获取复选框的状态。

方法:

  • ng-model用于获取选中的复选框。
  • 只需为 ng-model 设置不同的值,这些值将用于检查元素是否被选中。
  • 将为具有真实值的选定复选框弹出警报。

示例 1:

HTML


  

    
  
    

  

    

        GeeksForGeeks     

          

        Alternative of ng-checked to get          the checkbox's state in AngularJS     

       
        
            
                Checkbox1 :                                  
                Checkbox2 :                 
                Checkbox3 :                 
                Checkbox4 :                 
                
                                
        
    
  


HTML


  

    
  
    

  

    

        GeeksForGeeks     

          

        Alternative of ng-checked to get the          checkbox's state in AngularJS     

       
        
            
                Checkbox1 :                                  
                Checkbox2 :                 
                Checkbox3 :                 
                Checkbox4 :                 
                
                                
               

Selected Checkboxes = {{selCheckboxes | json}}

        
    
  


输出:

  • 点击按钮前:

  • 点击按钮后:

示例 2:

HTML



  

    
  
    

  

    

        GeeksForGeeks     

          

        Alternative of ng-checked to get the          checkbox's state in AngularJS     

       
        
            
                Checkbox1 :                                  
                Checkbox2 :                 
                Checkbox3 :                 
                Checkbox4 :                 
                
                                
               

Selected Checkboxes = {{selCheckboxes | json}}

        
    
  

输出: