kendo ui-为什么单击按钮刷新页面? [英] kendo ui - why do button click refresh the page?

查看:136
本文介绍了kendo ui-为什么单击按钮刷新页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请在下面找到我的代码:

Please find below my code:

客户搜索表单模板

<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>

customer-search.js,在该模板上方加载并创建viewmodel对象

customer-search.js where loading above template and creating viewmodel object

$(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页面.

When I click the search button, the text is set in the textbox but this also refresh the page with ?searchTxt=Search+clicked in the address bar.

我可以知道为什么该按钮单击刷新页面,以及如何停止刷新按钮单击刷新页面吗?

推荐答案

我将尝试为每个属性放置类型"属性,例如:

I would try and place the attribute 'type' for each like so:

<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事件处理程序.祝你好运.

The page thinks that each are performing a form submit action, but by placing the type attribute, you can access the event you intended for search. You may not need your form tags if you are not going to post any data, but rather just a js event handler. Good luck.

这篇关于kendo ui-为什么单击按钮刷新页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆