gpt4 book ai didi

javascript - html5表单验证多个表单多次提交

转载 作者:行者123 更新时间:2023-11-28 03:20:18 25 4
gpt4 key购买 nike

嗨,我有两个 div,其中包含输入字段并在提交时提交,单击其切换按钮,因此第一个包含电话号码并在提交时提交,单击将显示另一个包含 otp 字段的 div,并在此处提交我的 html5 表单验证不起作用。那么如何使用两个单独的提交对两种表单进行验证,在提交点击时编写切换逻辑。在代码片段中,第一个表单电话号码跳过验证

$("#num").click(function () {
$("#otpdiv").show();
$("#numberdiv").hide();
});

$("#otpbutton").click(function() {
$("#otpdiv").hide();
$("#detailsdiv").show();

});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.0/jquery.min.js"></script>
<!doctype html>
<html lang="en" class="no-focus">

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
<title>Users</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Muli:300,400,400i,600,700">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="css/isthara.css">


</head>

<body>
<form id="ebcharge">
<div class="row">
<div class="col-sm-12 text-center isthara-header">
<img class="logo" src="https://erp.isthara.com/assets/IstharaLogoNew1.png" width="10%" />
</div>

<div class="col-sm-12 isthara-welcome" id="numberdiv">
<h1>Welcome to the EB Charge</h1><br><br><br><br>

Phone Number:
<input type="tel" value="" pattern="^[789]\d{9}$" maxlength="10" placeholder="Enter Number" required><br><br>
<input id="num" type="submit" value="submit" required>

</div>
<div class="col-sm-12 isthara-welcome" id="otpdiv" style="display: none;">
<h1>Welcome to the EB Charge</h1><br><br><br><br>

OTP:
<input type="tel" value="" placeholder="Enter Number" required><br><br>
<input type="submit" id="otpbutton" value="submit">

</div>

<div class="col-sm-12 isthara-welcome" id="detailsdiv" style="display: none; margin: 30px;padding: 10px;">
<table class="table table-striped">
<tbody>
<tr>
<th scope="row">Name</th>
<td>Godwin </td>
</tr>
<tr>
<th scope="row">Property</th>
<td>Godwin </td>
</tr>
<tr>
<th scope="row">Room number</th>
<td>Godwin </td>
</tr>
<tr>
<th scope="row">Bed number</th>
<td>Godwin </td>
</tr>
<tr>
<th scope="row">Wallet amount balance</th>
<td>Godwin </td>
</tr>
<tr>
<th scope="row">KWH (G)</th>
<td>Godwin </td>
</tr>
<tr>
<th scope="row">Last read date and time</th>
<td>Godwin </td>
</tr>
<tr>
<th scope="row">Remarks - mandatory</th>
<td>Godwin</td>
</tr>
</tbody>
</table>
</div>

</div>
</form>
<script src="lib/jquery/jquery.min.js"></script>
<script src="js/main.js"></script>
</body>

</html>

c 用于切换,所以我不能使用单个提交,也可以尝试多种方式。

最佳答案

更改此行

<input id="num" type="submit" value="submit" required>

到那条线,验证将完美地工作

<input id="num" type="submit" name="numname" value="workingSubmit" />

<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<!doctype html>
<html lang="en" class="no-focus">

<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
<title>Users</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Muli:300,400,400i,600,700">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" href="css/isthara.css">


</head>

<body>
<form id="ebcharge">
<div class="row">
<div class="col-sm-12 text-center isthara-header">
<img class="logo" src="https://erp.isthara.com/assets/IstharaLogoNew1.png" width="10%" />
</div>

<div class="col-sm-12 isthara-welcome" id="numberdiv">
<h1>Welcome to the EB Charge</h1><br><br><br><br>

Phone Number:
<input type="tel" value="" pattern="^[789]\d{9}$" maxlength="10" placeholder="Enter Number" required><br><br>
<input id="num" type="submit" name="avto" value="submit">
<input id="num" type="submit" name="numname" value="working Submit button" />

</div>
<div class="col-sm-12 isthara-welcome" id="otpdiv" style="display: none;">
<h1>Welcome to the EB Charge</h1><br><br><br><br>

OTP:
<input type="tel" value="" placeholder="Enter Number" required><br><br>
<input type="submit" id="otpbutton" value="submit">

</div>

<div class="col-sm-12 isthara-welcome" id="detailsdiv" style="display: none; margin: 30px;padding: 10px;">
<table class="table table-striped">
<tbody>
<tr>
<th scope="row">Name</th>
<td>Godwin </td>
</tr>
<tr>
<th scope="row">Property</th>
<td>Godwin </td>
</tr>
<tr>
<th scope="row">Room number</th>
<td>Godwin </td>
</tr>
<tr>
<th scope="row">Bed number</th>
<td>Godwin </td>
</tr>
<tr>
<th scope="row">Wallet amount balance</th>
<td>Godwin </td>
</tr>
<tr>
<th scope="row">KWH (G)</th>
<td>Godwin </td>
</tr>
<tr>
<th scope="row">Last read date and time</th>
<td>Godwin </td>
</tr>
<tr>
<th scope="row">Remarks - mandatory</th>
<td>Godwin</td>
</tr>
</tbody>
</table>
</div>

</div>
</form>

</body>
<script>
$("#num").click(function () {
$("#otpdiv").show();
$("#numberdiv").hide();
});

$("#otpbutton").click(function() {
$("#otpdiv").hide();
$("#detailsdiv").show();

});
</script>
</html>

关于javascript - html5表单验证多个表单多次提交,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59218899/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com