剣道ui - ボタンをクリックするのはなぜページをクリックしますか?
-
26-12-2019 - |
質問
私のコードの下を見つけてください:
顧客検索フォームのテンプレート
<script type="text/x-kendoui-template" id="customer-search-view-template">
<div class="searchform" id="searchCustomer">
<form class="frmSearch">
<input name="searchTxt" data-bind="value: customerName" class="k-textbox" />
<button class="k-button" data-bind="click: searchClicked">Search</button>
<button class="k-button" data-bind="click: newClicked">New</button>
</form>
</div>
</script>
.
顧客検索。js上記のテンプレートとViewModelオブジェクトの作成
の作成$(function(){
var views = {};
templateLoader.loadExtTemplate("customer-search-view-template", "../views/customer-search-template.html");
var layout = new kendo.Layout($('#customer-search-view-template').html());
layout.render($("#main"));
// Create an observable view model object.
var customer = kendo.observable({
customerName: "John",
searchClicked: function() {
this.set("customerName", "Search clicked");
},
newClicked: function() {
this.set("customerName", "New clicked");
}
});
// Bind the view model to the personFields element.
kendo.bind($('#searchCustomer'), customer);
});
.
検索ボタンをクリックすると、テキストボックスにテキストが設定されますが、アドレスバーの?searchTxt=Search+clicked
でページを更新します。
解決
私はそれぞれのように属性 'type'を試してみてください。
<button type="button" class="k-button" data-bind="click: searchClicked">Search</button>
<button type="button" class="k-button" data-bind="click: newClicked">New</button>
.
それぞれがフォーム送信アクションを実行していると考えるが、type属性を配置することで、検索対象のイベントにアクセスできます。データを転記しないのではなく、JSイベントハンドラだけではない場合は、フォームタグが必要ない場合があります。頑張ってください。
所属していません StackOverflow