简体   繁体   中英

call function when button clicked

i want to call the action() only when the button is clicked. but its not happening :/

$(document).ready(function() {

         var window = $("#space"),
             undo = $("#button");

         undo.bind("click", function() { action(); });

         var onClose = function() { undo.show(); };

         if (!window.data("kendoWindow")) {

              window.kendoWindow({
                  width: "600px",
                  title: "Basic Reports ",
                  close: onClose
              });
         }
});

您可以简单地将action函数作为事件处理程序附加,如下所示:

$('#button').click(action);

You can use on instead of bind:

$("#button").on("click", function() {
    action();
});

From the jQuery API documentation:

As of jQuery 1.7, the .on() method is the preferred method for attaching event handlers to a document. For earlier versions, the .bind() method is used for attaching an event handler directly to elements. Handlers are attached to the currently selected elements in the jQuery object, so those elements must exist at the point the call to .bind() occurs. For more flexible event binding, see the discussion of event delegation in .on() or .delegate().

undo.bind("click", action);

您可以通过这种方式进行操作。

You are using jquery so simply use

$("#Your_button_id").click(function(){
    // place your coding here
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM