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>
posted @ 2018-02-27 11:01  Shaw_喆宇  阅读(1026)  评论(0编辑  收藏  举报