【发布时间】:2012-08-09 02:07:48
【问题描述】:
我有这个非常简单的可观察元素,由于某种原因在 IE8 中没有更新
<body>
<form data-bind="submit: show">
<input type="text" data-bind="value: someText" />
</form>
<script type="text/javascript">
var ViewModel = function () {
var self = this;
self.someText = ko.observable('initial value');
self.show = function () {
alert(self.someText());
self.someText('');
}
}
ko.applyBindings(new ViewModel());
</script>
</body>
所以,当点击回车时,输入到文本框中的值应该会显示出来。 Mozilla,Opera,chrome中的一切都很好。 IE 看不到任何更改,并且始终使用空字符串发出警报。为什么?
Here you can run this piece of code
【问题讨论】:
-
我不完全理解 IE 与其他浏览器相比的行为差异,但似乎没有触发更改事件在触发提交事件之前。 Knockout 依靠这些事件来保持视图模型是最新的。你可能需要调整你的代码来解决这个问题。
标签: internet-explorer data-binding knockout.js observable