2011-12-19 38 views
1

我有兩個HTML按鈕;一個提交表單,一個關閉容器對話框。按鈕關閉它不具有type屬性:IE錯誤地將HTML <button>作爲提交按鈕

<button type="submit">Submit</button> 
<button class="closeDialog">Close</button> 

中的JavaScript如下:

$(".closeDialog").live("click", function(event) { 
    event.preventDefault(); 
    $(this).parents(".dialog").dialog("close"); 
}); 

$("form.myClass").live("submit", function(event) { 
    event.preventDefault(); 
    // submits the form here . . . 
}); 

所有這一切都在每一個瀏覽器,但IE效果很好。在IE中,當點擊「關閉」按鈕時,上述兩個JavaScript事件都會執行,但只有.closeDialog事件處理程序應該執行。

IE似乎將一個元素視爲一個提交按鈕,不管它的type屬性如何。

在IE中如何解決這個誤解?

+0

也許增加你試過的IE版本/模式? (不知道它是否很重要) – Jeroen 2011-12-19 20:22:39

+0

什麼版本的IE?另外,也許嘗試? – 2011-12-19 20:23:25

+0

總是將類型按鈕設置爲按鈕,重置或提交,因爲每個瀏覽器可能有不同的處理...在渲染上設置默認值。 此外,建議使用type =「button」而不是「button」的輸入,因爲其行爲在表單內更具可預測性。 – Alfabravo 2011-12-19 20:24:51

回答

5

在第二個嘗試:<button type="button">

+2

IE不會錯誤地將其視爲提交,提交是默認設置。 – albert 2011-12-19 20:24:29

+1

顯然,「提交」是默認類型,在IE中只有。 – 2011-12-19 20:34:06

0

嘗試:

<input type='button' /> 

這將IE瀏覽器在大多數情況下。