请在下面找到我的代码:

客户搜索表单的模板

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

客户搜索。在上面加载模板和创建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的页面。

可以知道为什么这个按钮单击刷新页面,如何停止刷新页面按钮单击???

有帮助吗?

解决方案

我会尝试并为每个这样的属性'类型'放置:

<button type="button" class="k-button" data-bind="click: searchClicked">Search</button>
<button type="button" class="k-button" data-bind="click: newClicked">New</button>
.

页面认为每个都正在执行表单提交操作,而是通过放置类型属性,您可以访问您打算搜索的事件。如果您不打算发布任何数据,则可能不需要表单标记,而是仅仅是JS事件处理程序。祝你好运。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top