我正在一個網頁上有約8個HTML控件和一個HTML按鈕,使用它在8個HTML控件中的數據提交後點擊按鈕。 我想一旦按鈕使用JavaScript單擊以清除所有的8場,我有以下腳本onClick事件不工作後點擊一個HTML按鈕
HTML頁面
<td>
<select id="cbxProduct" data-bind="options: $root.productNames, optionsText: 'ProductName', optionsValue: 'ProductName', value: selectedChoice, optionsCaption: 'Product'">
</select>
</td>
<td>
<select id="cbxTerm" data-bind="options: $root.termNames, optionsText: 'TermName', optionsValue: 'TermName', enable: selectedChoice, value: selectedTerm, optionsCaption: 'Term'">
</select>
</td>
<td>
<input type="text" id="txbBVolume" placeholder="Bid Volume" data-bind="value: bidVolume" />
</td>
<td>
<select id="cbxBCP" data-bind="options: $root.counterpartyNames, optionsText: 'CounterPartyName', optionsValue: 'CounterPartyName', value: selectedBidCounterParty, optionsCaption: 'Bid CP'">
</select>
</td>
<td>
<input type="text" id="txbB" placeholder="Bid" data-bind="value: bid" />
</td>
<td>
<input type="text" id="txbO" placeholder="Offer" data-bind="value: offer" />
</td>
<td>
<select id="cbxOCP" data-bind="options: $root.counterpartyNames, optionsText: 'CounterPartyName', optionsValue: 'CounterPartyName', value: selectedOfferCounterParty, optionsCaption: 'Offer CP'">
</select>
</td>
<td>
<input type="text" id="txbOVolume" placeholder="Offer Volume" data- bind="value: offerVolume" />
</td>
<td >
<input type="button" class="btn btn-success" data-bind=" click: clear" value="Add New Entry" />
</td>
@section scripts {
<script src="~/App/ClearAllFields.js"></script>
}
淘汰賽JS
self.add = function (cc) {
var payload = {
Term: this.selectedTerm(), Product: this.selectedChoice(),
BidCP: this.selectedBidCounterParty(), BidVolume: (this.bidVolume() == "") ? null : this.bidVolume(), Bid: (this.bid() == "") ? null : this.bid(), Offer: (this.offer() == "") ? null : this.offer(),
OfferVolume: (this.offerVolume() == "") ? null : this.offerVolume(), OfferCP: this.selectedOfferCounterParty(), Locked: false, Sequence: "", TermID: 0, ProductID: 0
};
$.ajax({
url: '/odata/CC',
type: 'POST',
// data: ko.toJSON(payload),
data: JSON.stringify(payload),
contentType: 'application/json',
dataType: 'json'
});
this.selectedChoice("Product");
this.selectedTerm("Term");
this.selectedBidCounterParty("Bid CP");
this.bVolume("");
this.bid("");
this.offer("");
this.oVolume("");
this.selectedOfferCounterParty("Offer CP");
}
我以爲一切都很好它清除TextBox字段但不清除下拉框。
例如,我已經通過點擊"Add new entry"
按鈕提交product=abc, term=fall, bVolume=5, BCP=X, Bid=10, Offer=12, OCP=C, OVolume=6
有一次我按一下按鈕,它提交的數據,並清除所有的文本字段bVolume,投標,報價,oVolume並留下下拉框,因爲它們是
@ j08691是我不好,我已經編輯,現在的問題 – DoIt
找不到任何理由反對但不介意他們,如果留下評論是反對票的話,會有幫助。 – DoIt
難道是'data-bind ='點擊:添加''覆蓋'onclick'屬性? –