jQuery插件及表单验证

article/2025/10/1 3:57:31

一、自定义插件

前提:引入jquery-3.3.1.js

<script src="js/jquery-3.3.1.js" type="text/javascript"></script>

1、$.extend(对象1,对象2)  对象1继承对象2

/*自定义插件*/$(function(){//$extend(对象1,对象2) 对象1继承对象2//定义一个人类对象,属性;name sexvar person={"name":"东方不败","sex":"女"};var stu={};console.log($.type(stu));// //为stu继承person的所有属性$.extend(stu,person);console.log(stu);console.log("----------------------------");//三个参数var person={"name":"东方不败","sex":"女"};var stu={"age":18};var sb={};console.log(person);console.log(stu);console.log(sb);// $.extend(sb,stu,person);// console.log(person);// console.log(stu);// console.log(sb);

2、$.extend() 扩展jQuery类方法

$.extend({"sb":function(){console.log("这是我定义的方法");},"nb":function(){console.log(123);}});// $.sb();// $.nb();//求最大值(最小值)$.extend({//最大值"myMax":function(a,b){return a>b?a:b},"myMax2":function(){// console.log(arguments.length);// 打擂台的思想var max = arguments[0];//假设这个arguments数组中的第一个值为最大值// console.log(arguments[0]);for(var i = 0;i<arguments.length;i++){if(max < arguments[i]){max = arguments[i];}}return max;"myMin":function(){// console.log(arguments.length);// 打擂台var min = arguments[0];//假设这个arguments数组中的第一个值为最大值// console.log(arguments[0]);for(var i = 0;i<arguments.length;i++){if(min > arguments[i]){min = arguments[i];}}return min;}});// console.log($.myMax2(12,2,3,56));// console.log($.myMax2(1));// console.log($.myMax2());// console.log($.myMax2(1,2,3,4,5,6,6,7));// console.log($.myMin(22,3,2));

3、$.fn.extend() 扩展jQuery对象方法

//实现全选效果$.fn.extend({// 扩展jQuery对象方法"mydemo":function(){console.log("这是jQuery对象方法");// alert(123);}})// 如何调用jQuery对象方法// $.fn.extend() 存储在加载函数内  作用域// $.fn.mydemo();// console.log($("#oDiv").mydemo());$.fn.extend({// 全选的对象方法"demo1":function(){// 在对象方法中,$(this)代表将来谁调用了,就代表谁// console.log($(this));// $(this).each(function(){// 	$(this).prop("checked",true);// });// jQuery的特性中有一个隐式迭代器$(this).prop("checked",true);},"demo2":function(){$(this).prop("checked",false);}});$("#checkall").click(function(){//获取到复选框 调用对象方法demo1 设置所有复选框选中$("input:checkbox").demo1();});$("#qxcheckall").click(function(){//获取到复选框  调用对象方法demo1 设置所有复选框选中$("input:checkbox").demo2();});})

二、第三方插件:表单验证

插件名:jQuery Validation

该插件捆绑了一套有用的验证方法,包括URL和 电子邮件验证,同时提供了一个用来编写用户自定义方法的API。所有的捆绑方法默认使用英语作为错误信息,且已翻译成起37种语言。

如何使用jQuery Validation?

1、下载jQuery插件验证库----jquery.validate.js

2、将类库引入页面

<script src="js/jquery.validate.js" type="text/javascript"></script>

3、两种方式使用验证

 案例:表单验证

$(function(){// 获取表单标签调用插件激活的方法$("#formRegister").validate({rules:{// 账号必须有,不能为空username:{required:true,minlength:10},email:{required:true,email:true}},// 编写自定义错误信息messages:{// 账号必须有,不能为空username:{required:"账号不能为空",minlength:"账号必须10以上"},email:{required:"必填",email:"邮箱格式不正确"}}});
<h2>表单验证</h2><form id="formRegister" action="index.html" method = "get">账号:<input type="text" name = "username"><br>密码 <input type="password" name = "password"/><br>邮箱 <input type="text" name = "email"><br><!-- 网上 搜索日期插件 --><input type="date"><br><input type="submit" value = "注册"></form>


http://chatgpt.dhexx.cn/article/5c1lSSaw.shtml

相关文章

jq表单验证

<!DOCTYPE html> <html><head><title>手工实现表单验证</title><meta charset"utf-8" /><script src"scripts/jquery-1.11.3.js"></script></head><body><fieldset><legend>用户…

用jQuery实现表单验证

转载自&#xff1a;https://www.cnblogs.com/hellowzl/p/5612122.html ——选自《锋利的jQuery》&#xff08;第2版&#xff09;第5章的例题 5.1.5 表单验证 表单&#xff08;form&#xff09;作为 HTML 最重要的一个组成部分&#xff0c;几乎在每个网页上都有体现&#xff0…

jQuery-表单验证使用方法

目录 一、表单验证单词二、思维导图三、表单验证的使用方法四、复选框全选和取消全选 一、表单验证单词 二、思维导图 三、表单验证的使用方法 代码如下&#xff1a; <!DOCTYPE html> <html><head><meta charset"utf-8"><title><…

jQuery-表单校验

为什么要表单验证 1.减轻服务器的压力 2.保证输入的数据符合要求 常用的表单验证 日期格式表单元素是否为空用户名和密码E-mail地址身份证号码 表单选择器 语法 描述 示例 :input 匹配所有input、textarea、select和button 元素 $("#myform :input")选取…

jQuery实现表单验证

1.基于html表单&#xff0c;利用jQuery实现表单验证功能。 2.html基本结构和样式&#xff1a; 3.html代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <h…

JQuery-表单验证

1.什么是表单验证&#xff1f; 表单验证是javascript中的高级选项之一。 可用来在数据被送往服务器前对 HTML 表单中的这些输入数据进行验证。 2.为什么表单验证&#xff1f; 减轻服务器的压力 。 保证输入的数据符合要求。 3.案例 实现表单验证的案例在这里用GiWiFI页面…

SurfaceTexture

SurfaceTexture 类是在 Android 3.0 中引入的。就像 SurfaceView 是 Surface 和 View 的结合一样&#xff0c;SurfaceTexture 是 Surface 和 GLES texture 的粗糙结合&#xff08;有几个警告&#xff09;。 当你创建了一个 SurfaceTexture&#xff0c;你就创建了你的应用作为消…

UserWarning: findfont: Font family [‘sans-serif‘] not found. Falling back to DejaVu Sans

Python数据可视化分析时出现UserWarning: findfont: Font family [‘sans-serif’] not found. Falling back to DejaVu Sans…报错 原因&#xff1a;库中没有关于’Microsoft YaHei’的引用 换一种字体记一下 如 字体中文名称字体英文名称黑体SimHei宋体SimSun新宋体NSimSum…

The tag <fonta> is unrecognized in this browser. If you meant to render a React component, start its

写react 组件样式 styled-components 报错 是因为react 千万记住开头字母是大写 由于这个f小写了 但是这个是当成了一个组件在用 所以会一直报错 改为大写就会解决了 小伙伴们千万注意 react的项目组建开头必须大写

createfont(CreateFontIndirectW)

如何用CreateFont创建制定点大小的字符 import java.awt.Font; import java.io.File; import java.io.FileInputStream; public class Loadfont public static Font loadFont(String fontFileName, float fontSize) //第一个参数是外部字体名&#xff0c;第二个是字体大小 File…

MindFusion.WinForms Pack 2022.R2

MindFusion.WinForms Pack 2022.R2 每个节点多个标签-允许为单个流程图节点显示多个标题。您可以自定义节点标签&#xff0c;包括显示和定位。 混杂的 bhMoveLabels行为现在允许用户交互移动链接和节点标签。 水平偏移和垂直偏移现在适用于使用SetLinkLengthPosition方法定位的…

findfont: Font family [‘Times New Roman‘] not found. Falling back to DejaVu Sans.字体安装

问题描述 使用python对数据进行可视化的时候&#xff0c;matplotlib绘图的时候&#xff0c;提示警告如题所示&#xff1a; UserWarning: findfont: Font family [Times New Roman] not found. Falling back to DejaVu Sans. 环境说明&#xff1a;使用的是 CentOS系统&#xf…

Could not load file or assembly ‘office, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce11

Could not load file or assembly office, Version12.0.0.0, Cultureneutral, PublicKeyToken71e9bce11 window10 Could not load file or assembly office, Version12.0.0.0, Cultureneutral, PublicKeyToken71e9bce11 新的改变 我们对Markdown编辑器进行了一些功能拓展与语…

jasperreports6.12.2 could not load the following font解决方法

jasperreports通过Java代码生成PDF的时候不能获取中文字体&#xff0c;报错提示如下&#xff1a; net.sf.jasperreports.engine.JRRuntimeException: Could not load the following font: pdfFontName: STSong-Light pdfEncoding: Identity-H isPdfEmbedded : true本次环境&…

快速小巧的粘贴应用程序Hasty Paste

什么是 Hasty Paste? Hasty Paste 是一个快速粘贴文本并共享的地方&#xff0c;主要用于共享调试日志等&#xff0c;以帮助开发人员提供技术支持。该项目的目标是既快又小。 命令行安装 在群晖上以 Docker 方式安装。 官方的镜像没有发布在 docker hub&#xff0c;而是在 gh…

SpringBoot--解决BigDecimal传到前端后精度丢失的问题

原文网址&#xff1a;SpringBoot--解决BigDecimal传到前端后精度丢失的问题_IT利刃出鞘的博客-CSDN博客 简介 本文用示例介绍SpringBoot如何解决BigDecimal传到前端后精度丢失问题。 解决方案是&#xff1a;转成字符串格式返回。 问题描述 实例 Controller package com.…

BigDecimal 简单使用

目录 为什么使用BigDecimal 解决方案 构造方法 类型转换 double 转 BigDecimal BigDecimal 转 String BigDecimal 转 double/int/long等 加减乘除取余 divide 舍入模式 比较大小 格式化(DecimalFormat) 小结 为什么使用BigDecimal 1.float和double类型的主要设计目…

BigDecimal用法

文章目录 1、创建一个BigDecimal对象1.1、常用构造函数1.1、常用计算方法 2、BigDecimal很方便的几个用法2.1、用BigDecimal去除小数点后多余的0&#xff1a;stripTrailingZeros()2.2、BigDecimal的原值和科学计数值2.3、用BigDecimal比较大小&#xff1a;compareTo()2.4、BigD…

mysql bigdecimal查询_mysql bigdecimal

java学习:Java中的其它类 568x573 - 55KB - JPEG Java中BigDecimal类你了解多少?! 720x480 - 30KB - JPEG TypeHandlers 640x396 - 25KB - JPEG BigDecimal equals方法可能不相等 678x260 - 9KB - JPEG

BigDecimal 详解

一&#xff0c;BigDecimal的简介 Java在java.math包中提供的API类BigDecimal&#xff0c;用来对超过16位有效位的数进行精确的运算。 双精度浮点型变量double可以处理16位有效数。在实际应用中&#xff0c;需要对更大或者更小的数进行运算和处理。float和double只能用来做科学…