0
我想在輸入框中輸入的文本應用於單擊按鈕上的頁面。我正在使用提交綁定,但無法弄清楚我做錯了什麼。敲擊提交綁定點擊一個按鈕
HTML:
<form data-bind="submit: doSomething">
<label>
<input data-bind='value: showText' />
</label>
<button type="submit">button</button>
</form>
<h1><span data-bind='text: fullText'> </span></h1>
JS:
var ViewModel = function(text) {
this.showText = ko.observable(text);
this.doSomething : function(formElement) {
this.fullText = ko.computed(function(){
return this.showText();
}, this);
}
};
ko.applyBindings(new ViewModel());