div闪一下就消失

<div id="saveCode" class="center" style="display:none;width:300px;height: 350px;">
<form>
    <input type="image" id="cancel" onclick="cancel()"
           src="cancelIcon.png" style="position: relative;top:8px;left: 267px;height: 25px;">
    <div style="position: relative;top:15px;left: 58px;font-size: medium;">
        二维码ID:20142132948
    </div>
    <div style="position: relative;top:50px;left: 76px;background: grey;height: 150px;width: 150px;">

    </div>
        <input type="button" onclick="save()" value="保   存"
               style="position: relative;top: 90px;left: 92px;width: 115px;height: 40px;
          border: none;  font-size: large;color: white;background: #358DE6;">
</form>
</div>

下面是js:

function add() {
    document.getElementById("saveCode").style.display="block";
}
应该是点击上一个按钮后可以出现当前div,但实际上出现了一下就消失了,网页刷新了。
问题是formform表单默认提交你所填的数据,而你并没有写跳转的网页(form中有个action属性),因为连接为空 他就会刷新一次 导致你每次都是空的
解决方案直接删除<form></form>

转载于:https://www.cnblogs.com/xym4869/p/8477717.html

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值