禁用使用挖空.js动态创建文本框的特定文本框
Disable specific textbox from dynamic creation of textbox using knockout.js
我需要从动态创建的文本框列表中禁用特定的文本框。考虑我使用"创建按钮"动态创建 5 文本框的代码,我需要从中禁用第二个文本框。
<input type="button" value="Create TextBox" data-bind="click: addCourse"/>
<input type="button" value="Disable 2nd TextBox" data-bind="click: disable"/>
<div data-bind="foreach: cources">
<div>
<input type="text" data-bind="value: textValue,disable: disableStatus"/>
</div>
</div>
<div data-bind="foreach: cources">
<div>
<span type="text" data-bind="text: textValue"/>
</div>
</div>
JS代码:
function CourseViewModel(){
this.textValue = ko.observable('');
this.disableStatus = ko.observable(false);
}
function CeremonyViewModel() {
this.cources = ko.observableArray();
this.addCourse = function(){
this.cources.push(new CourseViewModel());
};
this.disable = function()
{
this.disableStatus(true);
}
}
ko.applyBindings(new CeremonyViewModel());
只需使用数组索引:
this.disable = function()
{
if (this.cources().length > 1) {
this.cources()[1].disableStatus(true);
}
}
http://jsfiddle.net/422b5ju7/1/
相关文章:
- onkeyup无法动态创建多个文本区域
- 文本表示法VS.构造函数,用于在JavaScript中创建对象
- 如何在 JavaScript 中创建输入文本框
- 如何在php中创建一个函数,该函数与文本区域一起工作,通过输入类似[color:red]的内容来打印具有等效颜色的文本
- 如何为动态创建的文本区域中输入的值更新ng模型
- 创建闪烁“;文本“;在javascript中
- 使用删除文本创建新行
- 使用其他页面上表单的文本创建链接
- 数组函数不适用于从元素文本创建的JavaScript数组
- 从空格分隔的文本创建和实现数组:AngularJS
- 由表达式文本创建的正则表达式是否共享单个实例
- 如何在 RaphaelJS 中根据需要为文本创建默认属性并链接其他属性
- 如何使用在用户输入后继续显示的前置文本创建文本字段
- 如何从 html 格式的文本创建元素
- 从文本区域中的选定文本创建列表html
- 在DIV中动态地围绕所选文本创建SPAN
- 在Jquery UI对话框中基于触发器锚点的文本创建动态按钮名称
- 如何在飞行中用文本创建链接?——JQuery初学者
- 从文本创建链接
- 如何仅为文本创建正则表达式模式