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

How to clear form data in layui

藏色散人
藏色散人Original
2020-11-24 11:15:085187browse

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>

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;
});

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!

Statement:
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