开发者

How do I invoke custom plugin on click?

开发者 https://www.devze.com 2023-01-02 23:29 出处:网络
I have the following code: (function(jQuery){ jQuery.fn.timepicker = function(){ return this.each(function(){

I have the following code:

(function(jQuery){
  jQuery.fn.timepicker = function(){
      return this.each(function(){
        jQuery(this).val("14:00");   
      });
  };
})(jQuery);

Currently I invoke thi开发者_运维技巧s function by the following code: $("#event_start_time").timepicker();

Where #event_start_time is the ID of an <input> field.

I do not want to invoke the plugin by using something like this:

$('#event_start_time"').click(function() {
  this.timepicker();
});

How can I invoke this code only when I click inside the text box?


Hmm... this place isn't as quick as it used to be :(

I found the answer. Here's the code:

(function(jQuery){
  jQuery.fn.timepicker = function(){
      return this.each(function(){
        obj = $(this);
        obj.click(function () {
          alert('test');
        });
    });
    };
})(jQuery);
0

精彩评论

暂无评论...
验证码 换一张
取 消