我想清除並重置我的輸入並使用knockoutJS選擇字段。下面是它如何工作的片段,但爲了簡潔起見進行了編輯。如何清除或重置輸入?
JavaScript代碼
view = (function()
{
var self = this;
self.anItem = ko.observable(new AnItem());
ko.applyBindings(self)
self.addItem = function()
{
self.somewhere.push(this);
self.anItem = new AnItem(); /////this doesn't clear the form
}
})();
function AnItem()
{
this.Name= "";
this.Type= 1
}
HTML代碼
<tfoot data-bind="with: anItem">
<tr>
<td><input type="text" data-bind="value= Name" /></td>
<td><select data-bind="options: pretendThisIsPopulated, optionsValue:'Value', optionsText:'Text', value:Type" /></td>
<td><a href="#" data-bind="click: addItem">add</a></td>
</tr>
</tfoot>
你可以添加jQuery到你的項目嗎?使用jQuery這將是一個簡單的 – ControlAltDel 2014-09-04 18:13:48