我有两个下拉列表和一个输入框。当从下拉列表中选择一个值时,应在其他两个控件中预先选择一个特定值。
这是我的淘汰赛代码:
var viewModel = {
templates: ko.observableArray(["Template1", "Template2"]),
//when Template2 is selected Spanish should be preselected from the languages select list and name of the template should be written in the folderName inputbox (Template2)
//when Template1 is selected French should be preselected and name of the template should be written in the folderName inputbox (Template1)
languages: ko.observableArray(["English", "Spanish", "French"]),
folderName: ko.observable()
}
ko.applyBindings(viewModel);
这是我的示例 html 代码:
<select id="templates" data-bind="options: templates"></select>
<div>
<input data-bind="value: folderName"/>
</div>
<div>
<select id="languages" data-bind="options: languages"></select>
</div>
选择 Template2 时,应从语言选择列表中预先选择西班牙语,并且应将模板名称写入 folderName 输入框 (Template2)。选择 Template1 时,应预先选择法语,并将模板名称写入 folderName 输入框(Template1)
小提琴:http: //jsfiddle.net/PsyComa/Q8unN/19/
我对javascript相当陌生,对工作示例的每一个帮助都会非常感激。谢谢你!