我有一個簡單的HTML表單,其中有幾個字段。如何防止「您確定要離開此頁面嗎?」提交表單提醒?
我想確保用戶在嘗試離開頁面時收到警告消息。所以我在頁面上添加了腳本,當用戶試圖離開這個頁面時,腳本就會運行。
但是,當用戶嘗試提交表單時,我也會收到此警報消息。當用戶保存表單時,我不想要此警報消息。
請幫忙。
下面是一些示例代碼。
<html>
<head>
<script>
function verifyexit() { return 'Are you sure ?'; } window.onbeforeunload = verifyexit;
</script>
</head>
<body>
Go to <a href="b.html"> another page </a>
<form action="c.html">
name : <input type="text" name="name" value=""/> <br>
email : <input type="text" name="email" value=""/> <br>
<input type="submit" value="save"/>
</form>
</body>
'你不能以標準方式綁定它請澄清。 –