All Components

MVVM / Event binding

Events log:

View source code

<div id="example">
    <button data-bind="events:{ click: listener, dblclick: listener, mouseover: listener, mouseout: listener }">Button</button>
</div>

View model source code

var viewModel = kendo.observable({
    listener: function(e) {
        kendoConsole.log("Event: " + e.type);
    }
});

kendo.bind($("#example"), viewModel);

HTML5/JavaScript 源码

<!DOCTYPE html>
<html>
 <head> 
  <title>Event binding</title> 
  <meta charset="utf-8"> 
  <link href="../content/shared/styles/examples-offline.css" rel="stylesheet"> 
  <link href="../../styles/kendo.common.min.css" rel="stylesheet"> 
  <link href="../../styles/kendo.rtl.min.css" rel="stylesheet"> 
  <link href="../../styles/kendo.default.min.css" rel="stylesheet"> 
  <link href="../../styles/kendo.dataviz.min.css" rel="stylesheet"> 
  <link href="../../styles/kendo.dataviz.default.min.css" rel="stylesheet"> 
  <script src="../../js/jquery.min.js"></script> 
  <script src="../../js/kendo.all.min.js"></script> 
  <script src="../content/shared/js/console.js"></script> 
  <script>
        
    </script> 
 </head> 
 <body> 
  <a class="offline-button" href="../index.html">Back</a> 
  <div id="example"> 
   <div class="demo-section k-content"> 
    <button class="k-button" data-bind="events: { click: listener, dblclick: listener, mouseover: listener, mouseout: listener }">Button</button> 
   </div> 
   <script>
        $(document).ready(function() {
            var viewModel = kendo.observable({
                listener: function(e) {
                    kendoConsole.log("Event: " + e.type);
                }
            });

            kendo.bind($("#example"), viewModel);
        });
    </script> 
   <div class="box wide"> 
    <h4>Events log:</h4> 
    <div class="console"></div> 
   </div> 
   <div class="box wide"> 
    <h4>View source code</h4> 
    <pre class="prettyprint">
<div id="example">
    <button data-bind="events:{ click: listener, dblclick: listener, mouseover: listener, mouseout: listener }">Button</button>
</div>
</pre> 
    <h4 style="padding-top: 2em;">View model source code</h4> 
    <pre class="prettyprint">
var viewModel = kendo.observable({
    listener: function(e) {
        kendoConsole.log("Event: " + e.type);
    }
});

kendo.bind($("#example"), viewModel);
</pre> 
   </div> 
   <style>
        .demo-section button {
            width: 200px;
            height: 60px;
        }

        .prettyprint {
            background-color: #fff;
            border: 1px solid #ccc;
            overflow: auto;
            padding: 5px;
        }
    </style> 
  </div>   
 </body>
</html>