表单验证系列(一):Table主页

技术栈:umi、React、ts、tea-component
搭建基础父级页面
在这里插入图片描述

import React, { useRef, useState, Fragment } from 'react';
import { useHistory  } from 'react-router-dom';
import {
  Layout,
  Card,
  Button,
  SearchBox,
  Table,
  Justify,
} from 'tea-component';

const { Content } = Layout;

export default function TestValidation() {
  const history = useHistory();

  return (
    <Content className="oit-layout--fixheader">
      <Content.Header title="表单校验"></Content.Header>
      <Content.Body full className="activitiesLists testValidation-cardBody">
        <Table.ActionPanel>
          <Justify
            left={
              <Button type='primary' onClick={() => history.push('/TestValidation/add')}>新增</Button>
            }
            right={
              <>
                <SearchBox />
                <Button icon="setting" />
                <Button icon="refresh" />
                <Button icon="download" />
              </>
            }
          ></Justify>
        </Table.ActionPanel>
        <Card>
          <Card.Body>
            <Table
              bordered
              records={[{
                key: '键名',
                value: '键值'
              }]}
              columns={[
                {
                  key: "key",
                  header: "Key",
                },
                {
                  key: "value",
                  header: "Value",
                },
                {
                  key: "",
                  header: "操作",
                  render: () => (
                    <Fragment>
                      <Button type='link' onClick={() => history.push('/TestValidation/edit')}>编辑</Button>
                      <Button type='link'>删除</Button>
                    </Fragment>
                  )
                },
              ]}
            />
          </Card.Body>
        </Card>
      </Content.Body>
    </Content>
  );
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
为了实现表单验证,我们可以在提交表单时检查表单中的输入是否符合要求。以下是一个简单的例子,展示如何使用 JavaScript 和 HTML 表格来验证表单中的输入: HTML 代码: ```html <form id="myForm" onsubmit="return validateForm()"> <table> <tr> <td><label for="name">Name:</label></td> <td><input type="text" id="name" name="name"></td> </tr> <tr> <td><label for="email">Email:</label></td> <td><input type="email" id="email" name="email"></td> </tr> <tr> <td><label for="age">Age:</label></td> <td><input type="number" id="age" name="age"></td> </tr> <tr> <td colspan="2"><input type="submit" value="Submit"></td> </tr> </table> </form> ``` JavaScript 代码: ```javascript function validateForm() { var name = document.forms["myForm"]["name"].value; var email = document.forms["myForm"]["email"].value; var age = document.forms["myForm"]["age"].value; if (name == "") { alert("Name must be filled out"); return false; } if (email == "") { alert("Email must be filled out"); return false; } if (age == "" || isNaN(age)) { alert("Age must be filled out with a number"); return false; } return true; } ``` 这个例子中,我们使用了 `document.forms` 对象来获取表单中输入的值,然后检查这些值是否符合要求。如果某个输入框没有填写或者填写了错误的值,我们会弹出一个警告框并返回 `false`,阻止表单提交。如果所有输入框都符合要求,我们返回 `true`,允许表单提交。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值