Home > Web Front-end > Layui Tutorial > How to clear form data in layui

How to clear form data in layui

藏色散人
Release: 2020-11-30 15:12:07
Original
5239 people have browsed it

Layui method of clearing form data: first create a form data; then implement monitoring submission; finally clear the form through "$("#addGoodsForm")[0].reset();".

How to clear form data in layui

Recommended: "layUI Tutorial"

The operating environment of this tutorial: windows10 system, layui2.5.6 version, the The method is applicable to all brands of computers.

layui clears and resets the form data

I have been using the layui framework recently. After the form data is submitted on the page, if the page form data is cleared, there is the following. Method

Form:

<form class="layui-form" action="" lay-filter="addGoodsForm" id="addGoodsForm">
 主题内容
</form>
Copy after login

jquery:

//监听提交
form.on(&#39;submit(upGoodsBtn)&#39;, function(data){
 var formDate = data.field;
 console.log(formDate);
 $.ajax({
  url: &#39;/goods/saveGoodInfos&#39;,
  type: &#39;POST&#39;,
  data: formDate,
  dataType: &#39;json&#39;,
  success: function (data) {
   if (data.success){
    top.layer.msg("商品发布成功了,等待管理员审核", {time:3000});
    // 清空表单 (“addGoodsForm”是表单的id)
    $("#addGoodsForm")[0].reset();
    layui.form.render();
   }else{
    top.layer.msg("商品发布失败,请重新发布吧!", {time:3000});
    // 清空表单 (“addGoodsForm”是表单的id)
    $("#addGoodsForm")[0].reset();
    layui.form.render();
   }
  }
 });
 return false;
});
Copy after login

Well, in the above callback function, a method to clear the form is written. Hope it helps you.

The above is the detailed content of How to clear form data in layui. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
How about layui framework?
From 1970-01-01 08:00:00
0
0
0
layui cannot be loaded
From 1970-01-01 08:00:00
0
0
0
Why is the reference to layui file invalid?
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template