我对IE10有意见。我使用knockout.js作为MVVM。我还使用输入验证来确保只接受数字值。验证之一是来自jquery.numeric的这里。在所有浏览器中,一切都很正常,但在IE10中则不然。使用IE10,验证是有效的,但是绑定不起作用,这意味着我无法获得从文本框输入的值,它始终是空的。请帮忙这是我的密码。
HTML和jQuery
<div class='liveExample'>
<p>With jquery.numeric: <input data-bind='value: withnumeric' id="withnumeric"/></p>
<p>With/Out jquery.numeric: <input data-bind='value: withoutnumeric' /></p>
<p><button data-bind="click: CompareBehavior" type="button">Submit</button>
</div>
$(document).ready(function(){
$('#withnumeric').numeric();
//this one doesn't work also
// $("#withnumeric").bind("keyup paste", function () {
// setTimeout(jQuery.proxy(function () {
// this.val(this.val().replace(/[^0-9]/g, ''));
// }, $(this)), 0);
//});
});ViewModel
var ViewModel = function() {
this.withnumeric = ko.observable();
this.withoutnumeric = ko.observable();
self.CompareBehavior = function () {
alert(this.withnumeric());
alert(this.withoutnumeric());
};
};
ko.applyBindings(new ViewModel());如果你想弹我的小提琴,请看这里,http://jsfiddle.net/Vs8yn/3/
发布于 2013-07-03 02:22:29
这似乎是Internet 10和jQuery-数值的兼容性问题。好消息是,您可以告诉Knockout使用其他事件(除了change)来更新绑定。在本例中,添加blur就足够了:
<input data-bind='value: withnumeric, valueUpdate: "blur"' id="withnumeric"/>jsFiddle:http://jsfiddle.net/Vs8yn/12/
发布于 2013-06-03 09:26:30
在您的jsFiddle中,您没有在加载时绑定视图模型:
$(function(){
ko.applyBindings(new ViewModel());
$('#withnumeric').numeric();
});您还需要用一个值初始化可观测值:
var ViewModel = function() {
var self = this;
self.withnumeric = ko.observable(0);
self.withoutnumeric = ko.observable(0);
self.CompareBehavior = function () {
alert(self.withnumeric());
alert(self.withoutnumeric());
};我更新了它,它似乎在IE10中工作。
https://stackoverflow.com/questions/16893352
复制相似问题