呼び出し時にイベントをロードできるようにプラグインを変更するにはどうすればよいですか?現在、プラグインはページの読み込み時に読み込まれ、.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()イベントの代わりにドキュメントロードでプラグインをトリガーします。