icn*_*icn 7 html javascript forms button twitter-bootstrap
这是我的代码
<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>
Run Code Online (Sandbox Code Playgroud)
我只想在单击添加按钮时向表中添加新行,但似乎单击添加按钮会触发表单提交.
不是只有一个按钮
type=submit
Run Code Online (Sandbox Code Playgroud)
提交表格.或者表单中的任何按钮都会触发表单提交?
Mau*_*ger 43
无需使用Javascript.只是设置type="button"为覆盖隐式type="submit".这也可以在HTML5规范中找到,如下所述:https://stackoverflow.com/a/9643866/2175370
Ant*_*ark 14
已经false在调用该函数返回onclick将阻止表单提交.:)
onclick="javascript:add_user_group(2);return false;"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
19014 次 |
| 最近记录: |