JS实现web前端提交功能,主要效果:用户评论后,在合适位置弹出“评论成功”,2秒钟后自动消失,提示用户评论成功。一起来看下如何实现。
{#评论成功提示#}
<div class="popup_con" style="display: none; margin-left: 300px">
<div class="popup" >
<p style="color: red; font-size: 16px">评论成功!</p>
</div>
<div class="mask"></div>
</div>// 评论成功提示定时器 // 定一定时器函数 function showSuccessMsg() { $('.popup_con').fadeIn('fast', function () { setTimeout(function () { $('.popup_con').fadeOut('fast', function () { }); }, 2000) }); } // 提交评论 $("#FORM_comment").submit(function (event) { event.PReventDefault(); var comment = $('#comment').val(); var data = { "comment": comment }; $.Ajax({ url: "/task_mgm/taskinfo_comment=" + taskId, type: "post", data: JSON.stringify(data), contentType: "APPlication/json", // 传给后端的数据类型 dataType: "JSON", // 接收后端的数据类型 success: function (resp) { if (resp.error == 'OK') { showSuccessMsg(); {#alert('评论成功');#} $('#comment').val(''); //清空评论框 } else { alert('评论失败'); } } }) })







网友评论文明上网理性发言 已有0人参与
发表评论: