带有HTML5按钮元素的确认对话框

时间:2017-04-02 22:55:40

标签: javascript html5

我有一个像这样的按钮元素:

<button name="command" type="submit" form="frmLandUnits" class="btn btn-danger" title="Delete" value="Delete:1:352404725228987" onclick="return confirm('Are you sure?');">
      <span class="glyphicon glyphicon-trash" aria-hidden="true">
    </span></button>

它是表格中的数据输入网格的一部分。在每一行上都有其他按钮,比如Update,还有一个带有Insert按钮的新行。问题是,当单击确定时,表单未提交。谷歌对此的搜索没有找到我能找到的任何东西。

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<form name="frmLandUnits" method="POST" action="https://httpbin.org/post">


<button name="command" type="submit" class="btn btn-danger" title="Delete" value="Delete:1:352404725228987" onclick="return confirm('Are you sure?');">
      <span class="glyphicon glyphicon-trash" aria-hidden="true">
    </span></button>
    
</form>

行为与onclick的行为不同input。这就是我认为这不是重复的原因。

2 个答案:

答案 0 :(得分:1)

只需从form中删除button属性。

<button name="command" type="submit" class="btn btn-danger" title="Delete" value="Delete:1:352404725228987" onclick="return confirm('Are you sure?');">
      <span class="glyphicon glyphicon-trash" aria-hidden="true">
    </span></button>

结帐this demo

答案 1 :(得分:0)

<form id="frmLandUnits" method="GET" action="www.microsoft.com" onsubmit="return confirm('Do you really want to submit the form?');"  >

<button name="command" type="submit" form="frmLandUnits" class="btn btn-danger" 
title="Delete" value="Delete:1:352404725228987" >
  <span class="glyphicon glyphicon-trash" aria-hidden="true">
</span></button>
</form>

希望这有帮助。