Knockoutjs Study notes (11)

Source: Internet
Author: User

Enable binding often acts on form elements, such as input, select, and textarea. Dom elements that contain enable binding determine whether they are available according to the true and false of the enable binding parameter.

A simple example is as follows:

HTML section:

1 <P>2     <inputtype= "checkbox"Data-bind= "Checked:hascellphone" />3 I have a cellphone.4 </P>5 6 <P>7 Your Cellphone number:8     <inputtype= "text"Data-bind= "Value:cellphonenumber, Enable:hascellphone" />9 </P>

JS section:

 1  function   Myviewmodel () { var  self = this  ;  3  4  self.cellphonenumber = "" ; 5  Self.hascellphone = ko.observable (false   6   7  8  ko.applybindings (new  Myviewmodel ()); 

The Enable binding parameter can be a function in ViewModel, or it can be any JavaScript judgment statement. If the argument is a observable, the UI will immediately update the enable state of the corresponding element whenever the observable changes, otherwise the UI will only set the enable state of the element once.

As for the use of disable binding can refer to the enable binding, the effect of the two is just the opposite.

Knockoutjs Study notes (11)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.