当前位置:网站首页>The problem that the page will refresh automatically after clicking the submit button on the form is solved
The problem that the page will refresh automatically after clicking the submit button on the form is solved
2022-04-23 06:06:00 【DK_ ten thousand and thirty-two】
First , All we have to do is , Click on button The button cannot let form Submit yourself , So here it is form Add one more onsubmit event , It is forbidden to submit .
<form onsubmit="return false">
So the way of submission , Just through js perhaps jq To complete , I used it here jQuery
$(function () {
$("#form").submit(function () {
});
});
Submit completed , Restore to default format with
if (data.status == 0) {
// Input succeeded
$("input:eq(0)").val("");
$("input:eq(1)").val(" SF EXPRESS ");
$("input:eq(2)").val("");
$("input:eq(3)").val("");
layer.alert(" Input succeeded ");
} else {
// Entry failed
layer.alert(" Entry failed ");
}
Here is the complete code , You can have a look at what you want to see
This is form Forms
<form id="form" class="layui-form layui-card-body" onsubmit="return false">
<div class="layui-form-item">
<label class="layui-form-label"> Odd Numbers </label>
<div class="layui-input-block">
<input type="text" name="code" required lay-verify="required" placeholder=" Please input the express number " autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label"> Courier Services Company </label>
<div class="layui-input-block">
<select name="company" lay-verify="" lay-search>
<option> China Post </option>
<option> Chile post </option>
<option> Medium speed express </option>
</select>
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label"> Recipient's name </label>
<div class="layui-input-block">
<input type="text" name="username" required lay-verify="required" placeholder=" Please enter the name of the consignee " autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<label class="layui-form-label"> Phone number </label>
<div class="layui-input-block">
<input type="text" name="phonenumber" required lay-verify="required" placeholder=" Please enter your mobile number " autocomplete="off" class="layui-input">
</div>
</div>
<div class="layui-form-item">
<div class="layui-input-block">
<button type="submit" class="layui-btn layui-btn-blue" > Submit... Immediately </button> </button>
<button type="reset" class="layui-btn layui-btn-primary"> Reset </button>
</div>
</div>
</form>
jQuery + ajax
This is jQuery + ajax
<script>
$(function () {
$("#form").submit(function () {
var loadId = layer.load();
var number = $("input:eq(0)").val();
var company = $("input:eq(1)").val();
var username = $("input:eq(2)").val();
var userPhone = $("input:eq(3)").val();
$.post("/express/insert.do", {
number: number,
company: company,
username: username,
userPhone: userPhone
}, function (data) {
// Close the prompt first Loading
layer.close(loadId);
// layer.alert(data);
if (data.status == 0) {
// Input succeeded
$("input:eq(0)").val("");
$("input:eq(1)").val(" SF EXPRESS ");
$("input:eq(2)").val("");
$("input:eq(3)").val("");
layer.alert(" Input succeeded ");
} else {
// Entry failed
layer.alert(" Entry failed ");
}
});
});
})
</script>
版权声明
本文为[DK_ ten thousand and thirty-two]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220534093419.html
边栏推荐
- 常用编程记录——parser = argparse.ArgumentParser()
- LDCT图像重建论文——Eformer: Edge Enhancement based Transformer for Medical Image Denoising
- 金蝶EAS“总账”系统召唤“反过账”按钮
- Conda 虚拟环境管理(创建、删除、克隆、重命名、导出和导入)
- JVM series (3) -- memory allocation and recycling strategy
- 线性代数第一章-行列式
- Fundamentals of digital image processing (Gonzalez) I
- 去噪论文阅读——[RIDNet, ICCV19]Real Image Denoising with Feature Attention
- String notes
- Pytorch notes - observe dataloader & build lenet with torch to process cifar-10 complete code
猜你喜欢
String notes
Configure domestic image accelerator for yarn
Anaconda安装PyQt5 和 pyqt5-tools后没有出现designer.exe的问题解决
You cannot access this shared folder because your organization's security policy prevents unauthenticated guests from accessing it
Pyqy5 learning (III): qlineedit + qtextedit
Pytoch learning record (x): data preprocessing + batch normalization (BN)
Implementation of displaying database pictures to browser tables based on thymeleaf
Contrôle automatique (version Han min)
PyQy5学习(四):QAbstractButton+QRadioButton+QCheckBox
Class loading and classloader understanding
随机推荐
Filebrowser realizes private network disk
图像恢复论文——[RED-Net, NIPS16]Image Restoration Using Very Deep Convolutional Encoder-Decoder Networks wi
Solve the error: importerror: iprogress not found Please update jupyter and ipywidgets
Exception handling: grab and throw model
Pytorch学习记录(十):数据预处理+Batch Normalization批处理(BN)
Pyqy5 learning (2): qmainwindow + QWidget + qlabel
常用编程记录——parser = argparse.ArgumentParser()
Get the value of state in effects in DVA
Anaconda
线性代数第三章-矩阵的初等变换与线性方程组
Pytorch learning record (XI): data enhancement, torchvision Explanation of various functions of transforms
Programming record - picture rotation function SciPy ndimage. Simple use and effect observation of rotate()
Write your own redistemplate
建表到页面完整实例演示—联表查询
container
JVM family (4) -- memory overflow (OOM)
Pytorch学习记录(十一):数据增强、torchvision.transforms各函数讲解
Pyemd installation and simple use
Development environment EAS login license modification
图解numpy数组矩阵