如果取消,js确认刷新页面

Ald*_*tec 2 javascript

所以我有一个表格,提交时需要确认.我正在使用Javascript确认提示.但是,如果有人点击取消,我不希望它刷新.我认为放一个空的其他声明会这样做,但看起来我错了.

不确定我需要做什么来确保如果有人在弹出窗口上按下取消它不会刷新.

JS确认代码

function postConfirm() {
   if (confirm('You will not have another chance after submitting to view your post. Please make sure it is exactly how you want it before continuing. ')) {
       yourformelement.submit();
   } else {

   }
}
Run Code Online (Sandbox Code Playgroud)

使用此JS函数的表单(如果需要)

<div id="uploadForm">
        <center>
          <form enctype="multipart/form-data" action="functions/post_upload.php" method="post">
            <input type="hidden" name="MAX_FILE_SIZE" value="99999999" />
            <div><textarea id="text" cols="70" rows="15" name="entry"></textarea></div>
            <p> Attach an image to this memory!</p>
            <input name="userfile" type="file"><br>
            <input type="submit" value="Submit" class="blueButton" onclick="postConfirm()"/></div>
          </form></center>
        </div>
Run Code Online (Sandbox Code Playgroud)

j08*_*691 8

更改:

onclick="postConfirm()"
Run Code Online (Sandbox Code Playgroud)

onclick="return postConfirm()"
Run Code Online (Sandbox Code Playgroud)

并在你的功能,使其他:

else {
    return false;
   }
Run Code Online (Sandbox Code Playgroud)

jsFiddle例子