【发布时间】:2009-12-31 01:10:35
【问题描述】:
如何修改我的插件以允许加载通话中的事件?现在插件在页面加载时加载,我希望它与 .blur() 或我想分配的任何事件一起工作。任何帮助将不胜感激:
// The Plugin
(function($) {
$.fn.required = function() {
return this.each(function() {
var $this = $(this), $li = $this.closest("li");
if(!$this.val() || $this.val() == "- Select One -") {
console.log('test');
if (!$this.next(".validationError").length) {
$li.addClass("errorBg");
$this.after('<span class="validationError">err msg</span>');
}
} else if($this.val() && /required/.test($this.next().text()) === true) {
$li.removeClass("errorBg");
$this.next().remove();
}
});
}
})(jQuery);
// The Event Call
$("[name$='_required']").required().blur();
它在 blur() 上不起作用,它在文档加载时触发插件而不是 .blur() 事件。
【问题讨论】:
标签: jquery events plugins bind