2011-08-27 78 views
0

我想在提交表單前使用確認框供用戶檢查。我用下面的表單標籤在我的腳本:在html中嵌入javascript函數

<form action="delete.php" method="POST" target="_blank" onsubmit="return confirm(\"Are you sure you want to delete it from the database?\");"> 

但它不工作,當我點擊「提交」按鈕,在「delete.php」將被執行。任何人都可以幫我弄清楚我出錯的地方嗎?我想知道是不是因爲這個「確認」函數是某種內聯樣式,我需要在<head>標籤中做一些參考?謝謝!

回答

1
onsubmit="return confirm('Are you sure you want to delete it from the database?');" 

測試,並工作。我不認爲你可以在標籤中轉義那樣的字符。

+0

你是對的!謝謝〜 – Michael

+0

啊,我不知道我是如何忽略逃逸字符的。一個轉義字符會在html中產生一個錯誤。 escape char只能用於JS only環境。 – Trevor