Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/448.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将这段代码转换为jQuery插件_Javascript_Jquery_Asp.net - Fatal编程技术网

Javascript 将这段代码转换为jQuery插件

Javascript 将这段代码转换为jQuery插件,javascript,jquery,asp.net,Javascript,Jquery,Asp.net,我正在使用以下代码: $('div.x').find('#y').live('click', function(e) { var aa = $(this); if (aa.find('a').length == 0) { aa.find('div.z').hide(); aa.find('input:submit').click(function(e) { //...................

我正在使用以下代码:

 $('div.x').find('#y').live('click', function(e) {

        var aa = $(this);

    if (aa.find('a').length == 0) {

        aa.find('div.z').hide();

        aa.find('input:submit').click(function(e) {
            //...................
        });

        aa.append('xxx');
        $('html, body').animate({ scrollTop: 100 });
    }
    e.preventDefault();

});


$('body').click(function(e) {
    $('div.tt').slideUp('slow');
});

$('div.uu').delegate('div.gg', 'click', function(e) {
    e.stopPropagation();
});

现在,我想把上面的代码插入jQuery插件。你能告诉我怎么做吗?如何从外部接受默认值,以便可以从外部获取div类,而不是将其硬编码在插件中?

您可以使用此选项,只需更改一些内容:

这是未经测试的,但我相信它应该有效:

/*
    Copyright (c) <Year> <First & Last Name>, <Your Web Site>

    Permission is hereby granted, free of charge, to any person obtaining
    a copy of this software and associated documentation files (the
    "Software"), to deal in the Software without restriction, including
    without limitation the rights to use, copy, modify, merge, publish,
    distribute, sublicense, and/or sell copies of the Software, and to
    permit persons to whom the Software is furnished to do so, subject to
    the following conditions:

    The above copyright notice and this permission notice shall be
    included in all copies or substantial portions of the Software.

    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
    LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
    OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
    WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
(function($){
    $.fn.pluginname = function(options) {
        var settings = $.extend({}, $.fn.pluginname.defaultOptions, options);

        return this.each(function() {
            var $this = $(this);


      $this.find('#y').live('click', function(e) {

          var aa = $(this);

          if (aa.find('a').length == 0) {

              aa.find('div.z').hide();

              aa.find('input:submit').click(function(e) {
                  //...................
              });

              aa.append('xxx');
              $('html, body').animate({ scrollTop: 100 });
          }
          e.preventDefault();

      });


      $('body').click(function(e) {
          $('div.tt').slideUp('slow');
      });

      $('div.uu').delegate('div.gg', 'click', function(e) {
          e.stopPropagation();
      });

        });
    };

    $.fn.pluginname.defaultOptions = {
    };
})(jQuery);

我发布了一个答案,但是如果你告诉我什么类型的东西是选项,那么我也可以给你一个例子,但是请看:太
$('div.x').pluginname();