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)