我想清除并重置我的输入并使用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