且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

未删除KnockoutJS必需/禁用的属性

更新时间:2023-12-05 12:42:04

您***使用Knockout自己的内置

You better use Knockout's own built-in disable binding-handler:

<input data-bind="disable: disabled, attr: { name: name, placeholder: placeholder, value: value, type: type }" />

请参见小提琴

或者,您可以检查条件中是否存在明显的真实性",以便如果不满足条件,淘汰赛将删除该属性.例如:

Alternatively, you can check for explicit 'truthfulness' in your condition so that Knockout will remove the attribute if the condition is not met. For example:

<input data-bind="attr: { disabled: disabled() === 'true', ...}" />

请参见此小提琴(在已禁用"输入中键入"true"以激活disabled ).

See this Fiddle (type 'true' in the 'disabled' input to activate disabled).