当前位置:网站首页>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
边栏推荐
- Traitement des séquelles du flux de Tensor - exemple simple d'enregistrement de torche. Utils. Données. Dataset. Problème de dimension de l'image lors de la réécriture de l'ensemble de données
- 域内用户访问域外samba服务器用户名密码错误
- 在Jupyter notebook中用matplotlib.pyplot出现服务器挂掉、崩溃的问题
- Pytorch学习记录(十):数据预处理+Batch Normalization批处理(BN)
- 线性代数第一章-行列式
- Pytorch学习记录(三):神经网络的结构+使用Sequential、Module定义模型
- 实操—Nacos安装与配置
- CONDA virtual environment management (create, delete, clone, rename, export and import)
- String notes
- Common programming records - parser = argparse ArgumentParser()
猜你喜欢
对比学习论文——[MoCo,CVPR2020]Momentum Contrast for Unsupervised Visual Representation Learning
Pytorch學習記錄(十三):循環神經網絡((Recurrent Neural Network)
Pyqy5 learning (III): qlineedit + qtextedit
Fundamentals of digital image processing (Gonzalez) II: gray transformation and spatial filtering
sklearn之 Gaussian Processes
Delete and truncate
Reading of denoising papers - [cvpr2022] blind2blind: self supervised image denoising with visible blind spots
Programming record - picture rotation function SciPy ndimage. Simple use and effect observation of rotate()
SQL injection
如何利用对比学习做无监督——[CVPR22]Deraining&[ECCV20]Image Translation
随机推荐
Treatment of tensorflow sequelae - simple example record torch utils. data. dataset. Picture dimension problem when rewriting dataset
Pytorch学习记录(九):Pytorch中卷积神经网络
SQL基础:初识数据库与SQL-安装与基本介绍等—阿里云天池
C3p0 database connection pool usage
Fundamentals of digital image processing (Gonzalez) I
Class loading and classloader understanding
Automatic control (Han min version)
Opensips (1) -- detailed process of installing opensips
Ptorch learning record (XIII): recurrent neural network
EditorConfig
Fact final variable and final variable
Pytorch learning record (7): skills in processing data and training models
Font shape `OMX/cmex/m/n‘ in size <10.53937> not available (Font) size <10.95> substituted.
The bottom implementation principle of thread - static agent mode
Pytorch——数据加载和处理
sklearn之 Gaussian Processes
Pytorch学习记录(七):处理数据和训练模型的技巧
Pytorch学习记录(四):参数初始化
Pyqy5 learning (4): qabstractbutton + qradiobutton + qcheckbox
Pytorch notes - get familiar with the network construction method by building RESNET (complete code)