Joh*_*ore 4 javascript knockout.js
如果您在Chrome中运行此小提琴,则选项框将正确填充选项A,B和C.但是,如果您使用Internet Explorer(版本8或9)运行它,则它不起作用.如何修复此小提琴以使其与Internet Explorer一起使用,但仍然使用虚拟元素?
http://jsfiddle.net/jeljeljel/2tUmP/
HTML
<script type="text/html" id="template">
<select id="type" name="type">
<option value="">-- Choose --</option>
<!-- ko foreach: types -->
<option data-bind="text: $data.desc, attr: { value: $data.id }"></option>
<!-- /ko -->
</select>
</script>
<div id="placeholder" data-bind="template: { name: 'template' }"></div>
Run Code Online (Sandbox Code Playgroud)
使用Javascript
function Model(){
var self = this;
self.types = ko.observable([]);
}
var model = new Model();
model.types().push({id: 0, desc:'A'});
model.types().push({id: 1, desc:'B'});
model.types().push({id: 2, desc:'C'});
ko.applyBindings(model);
Run Code Online (Sandbox Code Playgroud)
这可能是Internet Explorer的限制.
而不是虚拟元素,使用options绑定来填充<select>元素:
<select id="type" name="type"
data-bind="options: types, optionsText: 'desc', optionsValue: 'id', optionsCaption: '-- Choose --'">
</select>
Run Code Online (Sandbox Code Playgroud)
文档:http://knockoutjs.com/documentation/options-binding.html
| 归档时间: |
|
| 查看次数: |
691 次 |
| 最近记录: |