【发布时间】:2018-07-06 06:43:38
【问题描述】:
我想学习如何编写 Jquery 插件。这是我的正常功能并将其转换为 jquery 插件,您能建议我如何做到这一点。
这样我就可以很容易地理解如何将函数转换为插件。
function probe_Validity(element) {
var validate = true;
$(".required-label").remove();
var warnings = {
text: "Please enter Name"
};
element.find(".required").each(function() {
var form_Data = $(this);
if (form_Data.prop("type").toLowerCase() === 'text' && form_Data.val() === '') {
form_Data.after('<div class="required-label">' + warnings.text + '</div>').addClass('required-active');
validate = false;
}
if (validate) {
return true;
} else {
return false;
}
$(function() {
$(".required").on("focus click", function() {
$(this).removeClass('required-active');
$(this).next().remove();
});
});
});
}
【问题讨论】:
-
为什么每次找到需要的元素都要加上
$(function() { $(".required").on("focus click", function() { $(this).removeClass('required-active'); $(this).next().remove(); }); });???它不属于你的函数
标签: javascript jquery plugins jquery-plugins frontend