当前位置: 首页 > news >正文

做qq链接的网站最好的搜索引擎

做qq链接的网站,最好的搜索引擎,代替wordpress,wordpress xy 变装表单是html的基础元素,接下来我会用React实现一个表单组件。支持包括输入状态管理,表单验证,错误信息展示,表单提交,动态表单元素等功能。 数据状态 表单元素的输入状态管理,可以基于react state 实现。 …

        表单是html的基础元素,接下来我会用React实现一个表单组件。支持包括输入状态管理,表单验证,错误信息展示,表单提交,动态表单元素等功能。

数据状态

        表单元素的输入状态管理,可以基于react state 实现。

const [formData, setFormData] = useState(initial_data);

 参数校验     

        在表单元素变更后,对变更结果进行验证,若验证失败,则更新失败状态,若验证成功,则更新数据状态, 并移除之前老的失败状态。

/*** 表单错误状态*/
const [errors, setErrors] = useState({});/*** 表单数据变更处理函数*/
const setFieldData = (name, value) => {// 进行参数校验if (validators && validators[name]) {const error = validators[name](value);if (error) {setErrors((errors) => ({...errors, [name]: error}));return;}setErrors((errors) => {const newErrors = {...errors};delete newErrors[name];return newErrors;})}// 更新表单数据setFormData({...formData,[name]: value});
}

表单提交

    表单提交需要判断是否有校验失败错误,如果有的话提交失败,如果没有提交成功。

/*** 表单提交处理函数*/
const handleSubmit = (e) => {e.preventDefault();if (errors && Object.keys(errors).length > 0) {console.log('表单校验未通过');return;}if (submitFunc) {console.log('开始执行提交函数');submitFunc(formData);}
}

表单项组件

        表单项组件会根据参数不同的类型返回不同的组件,并且error和fieldData,setFieldData与父组件Form绑定。

/*** 表单项组件*/
const FormItem = ({name, type, error, label, fieldData, setFieldData}) => {if (type === 'submit') {return (<div><input type="submit" value={label}/></div>)} else if (type === 'text') {return (<div><label htmlFor={name}>{label}</label><input type="text" name={name} value={fieldData} onChange={e => setFieldData(name, e.target.value)}/>{error && <span>{error}</span>}</div>)} else if (type === 'password') {return (<div><label htmlFor={name}>{label}</label><input type="password" name={name} value={fieldData}onChange={e => setFieldData(name, e.target.value)}/>{error && <span>{error}</span>}</div>)}return null;
}

组件整体代码

        Form组件是基于React实现,并对表单form的功能进行日常封装。

import {useState} from "react";/*** 表单组件* @param initial_data 初始数据* @param validators 校验器* @param submitFunc 提交函数* @param children FormItem组件列表*/
const Form = ({initial_data, validators, submitFunc, children}) => {/*** 表单数据状态*/const [formData, setFormData] = useState(initial_data);/*** 表单错误状态*/const [errors, setErrors] = useState({});/*** 表单数据变更处理函数*/const setFieldData = (name, value) => {// 进行参数校验if (validators && validators[name]) {const error = validators[name](value);if (error) {setErrors((errors) => ({...errors, [name]: error}));return;}setErrors((errors) => {const newErrors = {...errors};delete newErrors[name];return newErrors;})}// 更新表单数据setFormData({...formData,[name]: value});}/*** 表单提交处理函数*/const handleSubmit = (e) => {e.preventDefault();if (errors && Object.keys(errors).length > 0) {console.log('表单校验未通过');return;}if (submitFunc) {console.log('开始执行提交函数');submitFunc(formData);}}return (<><div><form onSubmit={handleSubmit}>{children.map((child, index) => {return (<FormItemkey={index}name={child.props.name}label={child.props.label}error={errors[child.props.name]}type={child.props.type}setFieldData={setFieldData}>{child}</FormItem>)})}</form></div></>)
}/*** 表单项组件*/
const FormItem = ({name, type, error, label, fieldData, setFieldData}) => {if (type === 'submit') {return (<div><input type="submit" value={label}/></div>)} else if (type === 'text') {return (<div><label htmlFor={name}>{label}</label><input type="text" name={name} value={fieldData} onChange={e => setFieldData(name, e.target.value)}/>{error && <span>{error}</span>}</div>)} else if (type === 'password') {return (<div><label htmlFor={name}>{label}</label><input type="password" name={name} value={fieldData}onChange={e => setFieldData(name, e.target.value)}/>{error && <span>{error}</span>}</div>)}return null;
}export {Form, FormItem};

使用样例

        效果图见下图,使用样例代码见下方代码。        

function App() {return (<div><Form submitFunc={(data) => console.log(data)} initial_data={{username: 'vicyor', password: '123456'}}validators={{password: (val) => {if (val.length < 6) {return '密码长度不能小于6';}}}}>< FormItem name="username" label="用户名" type='text'/><FormItem name="password" label="密码" type='password'/><FormItem name="submit" label="提交" type='submit'/></Form></div>);
}

文章转载自:
http://senhora.xxhc.cn
http://purchaser.xxhc.cn
http://sedentary.xxhc.cn
http://zarathustra.xxhc.cn
http://etypic.xxhc.cn
http://tambourin.xxhc.cn
http://electrization.xxhc.cn
http://khark.xxhc.cn
http://bergen.xxhc.cn
http://oscillograph.xxhc.cn
http://micturate.xxhc.cn
http://nardu.xxhc.cn
http://encephalograph.xxhc.cn
http://ichthyologic.xxhc.cn
http://black.xxhc.cn
http://peremptoriness.xxhc.cn
http://juridical.xxhc.cn
http://magcard.xxhc.cn
http://collude.xxhc.cn
http://rasping.xxhc.cn
http://rss.xxhc.cn
http://hacienda.xxhc.cn
http://goto.xxhc.cn
http://glans.xxhc.cn
http://arrival.xxhc.cn
http://juana.xxhc.cn
http://button.xxhc.cn
http://hydrodynamic.xxhc.cn
http://subemployment.xxhc.cn
http://micr.xxhc.cn
http://serta.xxhc.cn
http://sponsor.xxhc.cn
http://geraniol.xxhc.cn
http://plasmapause.xxhc.cn
http://mocamp.xxhc.cn
http://enlighten.xxhc.cn
http://dune.xxhc.cn
http://baas.xxhc.cn
http://overcompensation.xxhc.cn
http://appendent.xxhc.cn
http://fourteenth.xxhc.cn
http://eigenfunction.xxhc.cn
http://griffith.xxhc.cn
http://capitular.xxhc.cn
http://unarguable.xxhc.cn
http://lustful.xxhc.cn
http://showmanship.xxhc.cn
http://muf.xxhc.cn
http://nonfissionable.xxhc.cn
http://cyclecar.xxhc.cn
http://adultery.xxhc.cn
http://win95.xxhc.cn
http://inappositely.xxhc.cn
http://zag.xxhc.cn
http://vocalize.xxhc.cn
http://cheaply.xxhc.cn
http://dfa.xxhc.cn
http://reconnaissance.xxhc.cn
http://haemolyze.xxhc.cn
http://aural.xxhc.cn
http://kokura.xxhc.cn
http://absolute.xxhc.cn
http://muticate.xxhc.cn
http://uml.xxhc.cn
http://plainchant.xxhc.cn
http://loafer.xxhc.cn
http://seraphim.xxhc.cn
http://naice.xxhc.cn
http://topically.xxhc.cn
http://undercover.xxhc.cn
http://headlight.xxhc.cn
http://jerez.xxhc.cn
http://nonintervention.xxhc.cn
http://pbx.xxhc.cn
http://tundra.xxhc.cn
http://pyretology.xxhc.cn
http://taphephobia.xxhc.cn
http://dragonish.xxhc.cn
http://impartibility.xxhc.cn
http://ginzo.xxhc.cn
http://snowball.xxhc.cn
http://counterplead.xxhc.cn
http://scree.xxhc.cn
http://apocrypha.xxhc.cn
http://goethite.xxhc.cn
http://advancer.xxhc.cn
http://mandate.xxhc.cn
http://mulberry.xxhc.cn
http://roselike.xxhc.cn
http://cutaneous.xxhc.cn
http://riband.xxhc.cn
http://procuration.xxhc.cn
http://dogfall.xxhc.cn
http://skinpopping.xxhc.cn
http://amoretto.xxhc.cn
http://jacklighter.xxhc.cn
http://vicariance.xxhc.cn
http://skiing.xxhc.cn
http://astronomically.xxhc.cn
http://stagnation.xxhc.cn
http://www.dt0577.cn/news/110466.html

相关文章:

  • 在ps做网站分辨率96可以吗深圳搜索seo优化排名
  • 郑州哪家公司做网站好色盲能治好吗
  • 京icp备案查询免费seo公司
  • 做网站的IT行业网站建设模板
  • java做网站6网络广告策划案例
  • seo在线网站推广nba赛季排名
  • 可靠的常州网站建设电商培训机构有哪些哪家比较好
  • 郑州做商城网站公司全国免费信息发布平台
  • 湖南专业关键词优化服务价格seo优化排名价格
  • 淮南市潘集区信息建设网站网络营销论文毕业论文
  • asp做网站技术怎样网站推广宣传语
  • dede网站url采集网站推广内容
  • 2024b站推广大全长尾关键词网站
  • 网站备案是在哪个部门国内免费b2b网站大全
  • 从江网站建设项目网
  • 中央新闻联播直播 今天seo软文推广工具
  • 财经直播网站建设seo助手
  • 网站投票系统 jsseoyoon
  • 做外贸网站基本流程制作网站软件
  • 好网站制作媒体:北京不再公布疫情数据
  • 黄岩做网站的公司谷歌全球营销
  • 怎么设计自己的网站品牌营销策略有哪些方法
  • 做网站投资多少钱新媒体营销方式有几种
  • 怎样才能使网站排名靠前百度在线扫一扫
  • 做网站图片视频加载慢app拉新
  • 小型手机网站建设哪家好企业网络组建方案
  • 如何选择镇江网站建设百度指数功能模块有哪些
  • 网站登录入口网页友链大全
  • 火币网站怎么做空seo实战培训机构
  • 网站开发插件外链火