【问题标题】:Load <input type="button"> link instead of <tr> link加载 <input type="button"> 链接而不是 <tr> 链接
【发布时间】:2012-08-30 11:59:36
【问题描述】:

我有一个包含很多表格行的表格&lt;tr&gt;

每个&lt;tr&gt; 作为buttonlink

这是我的一些代码

<form name="mycart" id="mycart" action="library/cartactivity.php?action=update" method="post">
   <table cellspacing="0">   
      <tr id="cart-list" onClick="document.location.href='index.php'">
         <td><button onclick="location.href='library/stockactivity.php';">Remove</button></td>
      </tr>
   </table>
   <input type="submit" value="submit"/>
</form>

我的问题是当我点击&lt;button&gt; 时它会加载&lt;input type="submit"&gt; 链接

但是,我将代码更改为

<form name="mycart" id="mycart" action="library/cartactivity.php?action=update" method="post">
    <table cellspacing="0">   
       <tr id="cart-list" onClick="document.location.href='index.php'">
          <td><input type="button"  onclick="location.href='library/stockactivity.php';" value="Remove" /></td>
       </tr>
    </table>
    <input type="submit" value="submit"/>
</form>

(我把&lt;button&gt;改成&lt;input type="button"&gt;

我的问题是当我点击&lt;input type="button"&gt; 时,它会加载&lt;tr&gt; 链接

有什么解决办法吗?

【问题讨论】:

    标签: html forms button anchor


    【解决方案1】:

    使用&lt;a&gt; 标签代替onclick。试试这个

    <a href="library/stockactivity.php" style="text-decoration: none;"><input type="button" value="Remove" /></a>
    

    【讨论】:

      【解决方案2】:

      您需要将return false; 添加到您的事件处理程序中:

      <button onclick="location.href='......'; return false;">Remove</button>
      

      这将阻止提交表单。

      【讨论】:

      • 抱歉,它会加载 &lt;tr&gt; 链接
      猜你喜欢
      • 2016-01-06
      • 1970-01-01
      • 2011-04-19
      • 1970-01-01
      • 2011-05-14
      • 1970-01-01
      • 1970-01-01
      • 2013-01-03
      • 2016-05-15
      相关资源
      最近更新 更多