2013-10-25 46 views
0

我有一個帶有兩個提交按鈕的表單。這不是問題;我可以做到這一點。我們切入追逐。這裏的HTML:帶有兩個「提交」輸入的HTML表單奇怪

<!-- Assume there's a lot more document here. --> 
<form action="place1.html" method="GET"> 
    <input type="submit" value="Go to Place 1!" /> 
    <input type="submit" formaction="place2.html" value="Go to Place 2!" /> 
</form> 

第一個按鈕完全按預期工作。第二個按鈕是奇怪的 - 它實際上是去place1.html,除非你點擊最右邊的十個左右的像素 - 然後它會去place2.html。有人知道這裏發生了什麼嗎?我已經在Google Chrome和Internet Explorer上對它進行了測試。它是我的HTML嗎?瀏覽器?我的電腦?

更新
好的,所以我禁用了頁面上的CSS - 這沒有什麼區別。無論如何,沒有任何類型的CSS定位輸入。我還從form標記中刪除了action屬性,並按照Agony的建議(無骰子)爲第一個提交按鈕添加了formaction屬性。 (我會保留這個,因爲它感覺更乾淨。)

這裏有一點我的環境。我實際上有三個按鈕包含在兩個字段集包含在一個表單中。現在,它可能是CSS上的div。

<form id="server-form" method="post"> 
    <input type="hidden" name="custID" value="@Model.CustomerID" form="server-form" /> 

    <div style="float: left; width: 50%;"> 
     <fieldset> 
      <legend>Fieldset One</legend> 
      <!-- Content goes here --> 
      <p><input type="submit" formaction="/page1.html" value="Go to Page 1" /> 
      <input type="submit" formaction="/page2.html" value="Go to Page 2" /></p> 
     </fieldset> 
    </div> 

<div style="float: right; width: 50%;"> 
    <fieldset> 
     <legend>Fieldset Two</legend> 
     <!-- More and different content goes here --> 
     <p><input type="submit" formaction="/page3.html" value="Go to Page 3" /></p> 
    </fieldset> 
</div> 

爲什麼沒有我之前透露的?我想保持的情況儘可能通用,看它是否縮小到我的具體實例之前,有任何愚蠢的事情,我只是失蹤。
如果它有所作爲,我也使用ASP.NET MVC 4與剃刀,但我不認爲這應該。

+0

當你說它的行爲有所不同,取決於你點擊的位置,我認爲css。你能鏈接到任何現場展示這個問題嗎? –

+0

@erquhart不幸的是,沒有;我擁有的例子都是在本地工作。 :(我會禁用CSS,看看有什麼,但是。 –

+0

@erquhart更新了這篇文章 - 裏面有一些CSS,大多是浮動的。 –

回答

0

我沒有發現這個使用Chrome,Firefox或IE的問題,但我建議像這樣設置你的HTML。

<form> 
<input type="submit" formaction="place1.html" value="Go to Place 1!" /> 
<input type="submit" formaction="place2.html" value="Go to Place 2!" /> 
</form> 

如果可能的話。否則,我希望看到它後面的CSS來確定爲什麼你的第二個按鈕是這樣的。

+0

我添加了一個更新 - 如果你想要的話請看原文。 –