form表单提交小问题

要开发一个发送给用户手机验证码的小功能。要求如图所示


输入手机号后点击提交


等待重新获取读秒结束后再次发送仍停留在该页面下。


我是用两个div控制的不同的显示,但是在点击重新发送后会出现页面刷新的情况。最终发现是由于form表单的按钮提交造成的。具体代码如下:

<!-- 输入手机号div -->
<div id="inputNum" style="width: 320px;margin-top: 100px;margin-left: 500px;">
<form id="form">
<span style="font-size: 20px;">输入手机号:</span>
<input id="sendMsgPhoneNum" type="text" />
<input id="checkCode" type="hidden""/>
<input id="sendText" type="hidden"/>
</form>
<input type="submit" value="提交" οnclick="sendMsg()"style="float: right;margin-top: -40px;"/>
</div>

<!-- 点击提交后跳转的div -->
<div id="sendMsg" style="display:none;width: 520px;margin-top: 100px;margin-left: 500px;">
<form id="repForm">
<span style="font-size: 20px;">手机号:</span>
<input id="repSendMsgPhoneNum" type="text"/>
<input id="BtnOk" type="submit" value="重新获取(0)" disabled="disabled" οnclick="repSendMsg()"/><br>
</form>
<span style="font-size: 20px;">验证码:</span>
<span id="checkCodeShow" style="color: red;font-size: 20px;"></span>
</div>


inputNum的div提交按钮在form表单之外,所以在第一次点击的时候可以实现div的转换并且页面没有刷新,而在点击senMsg的div中的按钮后页面会刷新,是由于这次的提交按钮在form表单之内。

最终更改方法:将<input id="BtnOk" type="submit" value="重新获取(0)" disabled="disabled" οnclick="repSendMsg()"/><br>中type="submit"更改为type="button"即可。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值