1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > 同一个表单form 两个按钮button 调用同一个submit() 给action附不同的参数

同一个表单form 两个按钮button 调用同一个submit() 给action附不同的参数

时间:2022-06-28 06:35:17

相关推荐

同一个表单form 两个按钮button 调用同一个submit() 给action附不同的参数

一个暂存一个发布,只是状态一不一样,需要带上表单内部元素的value,只能通过submit()方法,需要动态给action附参数。

代码片段如下。

<form method="post" id="newblog"><button id="publish" type="button">发布文章</button><button id="tempsave" type="button">暂存</button></form>$("#publish").on('click', function() {if (checklogin() && checktitle() && checkcontent() && checkcode()) {sweetAlert({title : "您的文章已发布 !",text : "Your blog has been published.",type : "success"}, function() {document.getElementById("newblog").action=".newBlogServlet?state=1";document.getElementById("newblog").submit();;});} else {return false;}});$("#tempsave").on('click', function() {if (checklogin() && checktitle() && checkcontent() && checkcode()) {sweetAlert({title : "您的文章已保存 !",text : "Your blog has been saved.",type : "success"}, function() {document.getElementById("newblog").action=".newBlogServlet?state=0";document.getElementById("newblog").submit();});} else {return false;}});

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。