jQuery如何封装输入框插件

2020-05-23 06:22:13易采站长站整理

(10)获取值,重置值实现


//获取输入框值
getValue: function() {
return this.input.val();
},
//设置输入框值
setValue: function(str) {
this.input.val(str);
}

(11)定制化输入框接口


// 默认参数
$.fn.CreateInput.defaultValue = {
// 输入框类型:text,password
type: "text",
//输入框规则
spec: null,
//长度
length: null,
//描述输入字段
placeholder: null,
//是否必填
isRequired: false
};

【如何调用】


//生成输入框
$("#username").CreateInput({
type: "text",
spec: /^[0-9]d*$/,
length: '5-8',
placeholder: '不能为空,只能输入数字,长度为5-8',
isRequired: true
});
//调用公有方法
var myInput = $("#username").data('CreateInput');
myInput.setValue("1245");

以上所述是小编给大家介绍的jQuery如何封装输入框插件,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对软件开发网网站的支持!