Javascript-форум (https://javascript.ru/forum/)
-   jQuery (https://javascript.ru/forum/jquery/)
-   -   Отслеживание событий плагина (https://javascript.ru/forum/jquery/69213-otslezhivanie-sobytijj-plagina.html)

elink12 06.06.2017 16:49

Отслеживание событий плагина
 
Друзья, подскажите как отследить действия по созданному объекту. Фактически в div создается input и хочется понимать когда в нем происходит событие keyup или focus

<div class="title"></div>

<script>
(function($, window, document) {
    "use strict";

    var pluginName = "test",
        defaults = {
            animation: "Y",
        };
    function Test (element, options, event) {
        this.element = element;
        this._init();
    }
    Test.prototype = {
        _init: function () {
	      $(this.element).addClass('search-user form-control');
	      $(this.element).append('<input type="text"  placeholder="Введите 2 символа" >');
        },
    };
  $.fn.test = function(options,event) {
    this.each(function(){
       return  new Test(this, options, event);
    });
  };


})(jQuery, window, document);

$( document ).ready(function() {
    $(".title").test({animation:"Y"},event);
});

</script>

рони 06.06.2017 19:17

elink12,

как вариант ...
<!DOCTYPE html>

<html>
<head>
  <title>Untitled</title>
  <meta charset="utf-8">
  <style type="text/css">
  </style>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>

 <script>
(function($, window, document) {
    "use strict";

    var pluginName = "test",
        defaults = {
            animation: "Y",
        };
    function Test (element, options, event) {
        this.element = element;
        this._init();
    }
    Test.prototype = {
        _init: function () {
        $(this.element).addClass('search-user form-control');
        var inp = $('<input type="text"  placeholder="Введите 2 символа" >')
        $(this.element).append(inp);
        inp.focus(function() {
         $("body").trigger("testfocus");
         })
        },
    };
  $.fn.test = function(options,event) {
    this.each(function(){
       return  new Test(this, options, event);
    });
  };


})(jQuery, window, document);

$( document ).ready(function() {
    $(".title").test({animation:"Y"},event);
    $("body").bind("testfocus", function(event){alert(123)});


});

</script>

</head>

<body>
<div class="title"></div>

</body>
</html>


Часовой пояс GMT +3, время: 10:04.