我要做的就是让 KnockOut 将两个文本框的值相加,然后将结果放入第三个。
我在这里有一个 JSFiddle:jsFiddle
我的 HTML 框是:
<input data-bind="value:AirportPickup" data-val="true" data-val-number="The field Airport Pickup £10 per person must be a number." data-val-required="The Airport Pickup £10 per person field is required." id="AirportPickup" name="AirportPickup" type="text" value="0" />
<input data-bind="value:PackedLunch" data-val="true" data-val-number="The field Packed Lunch £6.50 must be a number." data-val-required="The Packed Lunch £6.50 field is required." id="PackedLunch" name="PackedLunch" type="text" value="0" />
<input data-bind="value:Breakfast" data-val="true" data-val-number="The field Breakfast £6.00 must be a number." data-val-required="The Breakfast £6.00 field is required." id="Breakfast" name="Breakfast" type="text" value="0" />
...我的 jQuery 是:
$(document).ready(function () {
function AppViewModel() {
this.AirportPickup = ko.observable("");
this.PackedLunch = ko.observable("");
this.Breakfast = AirportPickup + PackedLunch;
}
ko.applyBindings(new AppViewModel());
});
但是,当我将任何内容放入前两个文本框中时,什么也没有发生。
有人可以帮忙吗?
谢谢