繁体   English   中英

引导HTML单击按钮,无需提交表单

[英]bootstrap html click button without submit form

这是我的代码

        <form class="form-horizontal">

          <div class="control-group">
            <div class="controls">
              <button onclick="javascript:add_user_group(2);" class="btn">add</button>
            </div>
          </div>

        <table id="users-table" class="table table-striped" >
          <thead>
            <tr>
              <th>User Name</th>
              <th>Delete</th>            
            </tr>
          </thead>
          <tbody>

          </tbody>
        </table>

      </form>             

我只想在单击添加按钮时向表中添加新行,但是似乎单击添加按钮会触发表单的提交。

不只是一个按钮

 type=submit

提交表格。 或表单中的任何按钮都会触发表单的提交?

无需使用Javascript。 只需将type="button"为覆盖隐式type="submit" 也可以在此处提到的HTML5规范中找到: https : //stackoverflow.com/a/9643866/2175370

在名为onclick的函数中返回false将阻止表单提交。 :)

onclick="javascript:add_user_group(2);return false;"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM