【问题标题】:How to change a HTML template while developing a jQuery plugin如何在开发 jQuery 插件时更改 HTML 模板
【发布时间】:2016-02-16 10:10:13
【问题描述】:

假设我正在使用以下模板使用 jQuery 制作弹出插件。以下代码位于默认选项中的 jQuery 插件文件中。

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

所以,我想根据用户传递的参数更改title

$('#test').pop_up({
    'title': 'this title i want to use'
});

完整代码

(function($){
    $.fn.extend({ 
        pop_up: function(options) {

            //Settings list and the default values
            var defaults = {
                template: '<div class="popup"><div class="title"></div></div>',
                title: 'Hello',
                content: 'Are you sure to continue?'
            };
            
            var options = $.extend(defaults, options);
            $(this).each(function () {
                var $this = $(this);
                $this.on('click', function (e) {
                    e.preventDefault();
                  $(options.template).find('.title').html(options.title); //here 
                });
            });
        }
    });
})(jQuery);

【问题讨论】:

  • 你在HTML 中只使用jquery.js 吗?或者给我你用于页面的库名称
  • 请将您的插件代码添加到问题中。
  • 请检查我是否添加了代码

标签: javascript jquery html jquery-plugins


【解决方案1】:
 <!-- Include jQuery Popup Overlay -->
  <script src="http://vast-eng.github.io/jquery-popup-overlay/jquery.popupoverlay.js"></script>

  <script>
    $(document).ready(function() {
      // Initialize the plugin
      $('#my_popup').popup();
    });
  </script>

试试这个 js 可以轻松找到更多Click here

【讨论】:

  • 其实我想开发我的插件
猜你喜欢
  • 1970-01-01
  • 2021-07-20
  • 2010-12-18
  • 1970-01-01
  • 1970-01-01
  • 2011-05-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多