剣道ui - ボタンをクリックするのはなぜページをクリックしますか?

StackOverflow https://stackoverflow.com//questions/24061265

  •  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イベントハンドラだけではない場合は、フォームタグが必要ない場合があります。頑張ってください。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top