2015-11-18 18 views
-2

這是我的取消選中框代碼:angularjs複選框,它aumatically檢查時,頁面加載但不能在第一未選中嘗試

我使用JavaScript onpageload爲得到我選中複選框時頁面加載。

function checkBox() 
{ 
    test = document.getElementsByTagName("md-checkbox"); 

    for (i=0;i<test.length;i++) 
    { 
     if(test[i].getAttribute("aria-checked")=="false") 
     { 
      test[i].setAttribute("aria-checked","true"); 
      test[i].setAttribute("class","ng-valid md-default-theme md-checked ng-dirty ng-valid-parse ng-touched"); 
     } 
    } 
} 

但現在,當我嘗試取消選中它時,它僅在第二次單擊時未選中。 那麼我能做些什麼來解決這個問題?

+0

我取消選中框代碼: user3573919

+0

什麼是aria -checked?你可以使用ng-checked =「false」或ng-checked =「true」 – hurricane

回答

0

當你初始化你的html時,你可以使用兩種類型的表達式來表示複選框;

NG-模式

<input type="checkbox" ng-model="isCheckBoxTrue"> 

NG-檢查

<input id="checkSlave" type="checkbox" ng-checked="false" aria-label="Slave input"> 

對於你的榜樣;

function checkBox() { 
    test = document.getElementsByTagName("md-checkbox"); 
    for (i=0;i<test.length;i++) 
    { 
     if(test[i].getAttribute("ng-checked")=="false") 
     { 
      test[i].setAttribute("ng-checked","true"); 
      test[i].setAttribute("class","ng-valid md-default-theme md-checked ng-dirty ng-valid-parse ng-touched"); 
     } 

    } 
} 
+0

非常感謝你 – user3573919

+0

@ user3573919如果它是有用的,你可以申請我的答案嗎? – hurricane

+0

它還沒有工作yet.not未選中第一次點擊 – user3573919

相關問題