KnockoutJs學習筆記(十一)

來源:互聯網
上載者:User

標籤:style   blog   color   java   使用   io   for   ar   div   

enable binding往往作用於form elements,比如input、select和textarea等。包含enable binding的DOM元素會依照enable binding參數的真假來決定自己是否可用。

一個簡單的例子如下:

html部分:

1 <p>2     <input type="checkbox" data-bind="checked: hasCellphone" />3     I have a cellphone.4 </p>5 6 <p>7     Your cellphone number:8     <input type="text" data-bind="value: cellphoneNumber, enable: hasCellphone" />9 </p>

js部分:

1 function MyViewModel() {2     var self = this;3 4     self.cellphoneNumber = "";5     self.hasCellphone = ko.observable(false);6 }7 8 ko.applyBindings(new MyViewModel());

enable binding的參數可以是viewModel中的函數,也可以是任意的javascript判斷語句。如果說參數是一個observable,則每當該observable變化時,UI就會立即更新相應元素的enable狀態,否則,UI只會對元素的enable狀態設定一次。

至於disable binding的使用方法完全可以參照enable binding,兩者的效果只是剛好相反罷了。

KnockoutJs學習筆記(十一)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.