@ryleigh
To enable or disable a button using Knockout.js, you can bind the button's disabled attribute to a observable property in your view model. Here's how you can do it:
1
|
<button data-bind="disabled: isButtonDisabled">Click me</button> |
1 2 3 4 5 |
var viewModel = {
isButtonDisabled: ko.observable(false)
};
ko.applyBindings(viewModel);
|
1 2 3 4 5 |
// To disable the button viewModel.isButtonDisabled(true); // To enable the button viewModel.isButtonDisabled(false); |
By setting the value of the isButtonDisabled property to true, the button will be disabled. And by setting the value to false, the button will be enabled. This allows you to dynamically control the button's state based on certain conditions in your application.