【发布时间】: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