2013-10-25 47 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

我添加了一个更新 - 如果你想要的话请看原文。 –