问题描述
请参见下面的简单示例;绑定到计算的可观察对象的文本框.我的问题是,更新文本框时,IE会两次调用 write 方法. Firefox和其他浏览器似乎没有此问题.我已经在IE 7和更高版本中观察到了此问题. 8.
Please see the simple example below; a text box that is bound to a computed observable. My problem is that IE calls the write method twice when the text box is updated. Firefox and other browsers do not appear to have this problem. I have observed this issue in IE 7 & 8.
首先,我做错什么了吗?如果没有,推荐的处理方法是什么?
First of all, am I doing something wrong? If not, what is the recommended approach to deal with it?
<script>
var viewModel = {
myTestVar: "aaa"
};
viewModel.myTest = ko.computed({
read: function () {
return viewModel.myTestVar;
},
write: function (value) {
alert(value);
viewModel.myTestVar = value;
},
owner: viewModel
});
$(document).ready(function () {
ko.applyBindings(viewModel);
});
</script>
</head>
<body>
<input data-bind="value:myTest",type="text" style="width:150px;" />
</body>
推荐答案
value
绑定有一个特殊的部分,用于处理Internet Explorer中的自动完成.这通常会导致两次写入.如果您不关心自动完成功能,可以通过在input
:
The value
binding has a special section for dealing with auto-complete in Internet Explorer. This will often cause two writes. You can turn it off if you don't care about auto-complete by adding an attribute to the input
:
<input data-bind="value:myTest" type="text" style="width:150px;" autocomplete="off" />
这篇关于在Internet Explorer中两次敲除ockout.js计算的observable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!