再做一个支付界面,用POST提交各种数据,在金额和商品名称那里不能为空,毕竟没钱数怎么支付.
开始用如下JS代码实现弹出
<form name=alipayment action=pay.php method=post target="_blank">
<input type="text" id="money" name="money" value="" placeholder="请输入金额" autocomplete="off">
</form>
<script type="text/javascript">
function checkform(){
var name= document.getElementById('money');
if(name.value.length==0){
alert('输入为空!');
}
}
</script>
可是这种情况在不输入金额的情况下是弹出来输入为空,但有一个问题就是还是会跳转FORME里的链接,总觉的不好
后来改为
<form name=alipayment action=pay.php method=post target="_blank">
<input type="text" name="money" value="" placeholder="请输入金额" required="required" autocomplete="off">
</form>
不但省去了JS代码,更简洁,还不会跳转,照样达到了同样的效果!
required="required"
在input里加上表示必须要填写的,不填是不会继续的意思!
本文链接:https://www.dnwfb.com/1548.html,转载请注明出处。
评论0