2010-09-27 25 views
0

這裏提交的是我的代碼:形式正在對點擊圖像

<form action="telecallerinfo.php?action=modify&id=<?php echo $id;?>" method="post" enctype="multipart/form-data"> 
<table class="panel1"> 
    <tr> 
     <td>Caller Name:&nbsp;<input name="tele_caller" type="text" size="15" value="<?php echo $tele_caller?>" /></td> 
    </tr> 
    <tr> 
     <td align="right"> 
     <input name="submit" id="submit" type="image" src="images/submit.gif" width="60" onclick="this.form.submit();"/> 
     <input name="cancel" id="cancel" type="image" src="images/cancel.gif" width="60" onclick="window.location.href='telecallerinfo.php';"/> 
     </td> 
    </tr> 
</table> 
</form> 

但後來我點擊取消圖像上。表格正在提交。如何阻止它,因爲我只想刷新頁面。有沒有給圖像賦予復位功能的方法?

回答

2
<a href="telecallerinfo.php"><img src="images/cancel.gif" alt="DON'T FORGET ALTERNATIVE TEXT"></a> 
0

就試試這個

<input type="image" src="butup.gif" alt="Submit button"> 

一些瀏覽器「替代」選項卡中不會支持,所以還有另外一種方法:點擊後

<html> 
    <body> 
    <form action="example.cgi" method="post"> 
    <input type="text" name="login"> 
    <br> 
    <input type="image" src="submit.gif"> 
    <input type="image" src="reset.gif"> 
    </form> 
    </body> 
    </html> 
+0

不工作.... – champ 2010-09-27 08:37:50

+0

可能是您的瀏覽器忽略「alt」。 – Rupeshit 2010-09-27 08:51:47

+0

嘗試這一個: <形式行動= 「example.cgi」 方法= 「POST」>
Rupeshit 2010-09-27 08:52:11

0
<input type="reset" name="Reset" id="button" value="Reset" /> 
+0

,但我需要使用圖像.. – champ 2010-09-27 08:37:14

3

圖像輸入提交表單。您需要在事件處理程序中使用return false來停止正在進行的按鈕操作。

<input name="cancel" id="cancel" type="image" src="images/cancel.gif" width="60" onclick="window.location.href='telecallerinfo.php'; return false;"/> 

理論上同樣要保持提交 - 圖像,但實際上你應該丟棄的事件處理程序,並讓默認操作單擊時提交表單。

對於只是導航到頁面的按鈕,您最好使用簡單的鏈接。

有什麼辦法給圖像賦予復位功能嗎?

如果你真的想:

<img onclick="document.getElementById('someform').reset();"> 

但它會更好使用一個真正的復位按鈕做沒有JS:

<button type="reset"> 
    <img src="images/cancel.gif" alt="Reset"/> 
</button> 

這會給你一個按鈕圖形周圍圖像,但你可以擺脫與CSS:

border: none; padding: 0; margin: 0; background: transparent; 

您確定要「重置」嗎?他們是很少有用的,如果不小心點擊想他們提交按鈕往往討厭...

+0

thanxx我所有的問題就解決了... – champ 2010-09-27 10:14:24

+0

謝謝你的信息‘點擊後輸入圖像提交表單’。所以 – Sumia 2017-01-23 11:21:12

2

,如果你想爲圖像你可以試試這個:

<button type="reset"> 
<img src="image location" alt="Reset" /> 
</button> 

它的工作原理,但,重置按鈕具有破壞性,並且不應使用 ,除非在需要銷燬用戶輸入的情況下真的是 。