Layui method of clearing form data: first create a form data; then implement monitoring submission; finally clear the form through "$("#addGoodsForm")[0].reset();".
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:
jquery:
//监听提交 form.on('submit(upGoodsBtn)', function(data){ var formDate = data.field; console.log(formDate); $.ajax({ url: '/goods/saveGoodInfos', type: 'POST', data: formDate, dataType: 'json', 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!