我有一个从 PHP 请求返回的表单。该表单有一个提交按钮和一个常规按钮。提交似乎工作得很好,但常规的不行!请指教。
这是我的 HTML:
<tr id='actionRow' name='actionRow' hidden='hidden'>
<td>
<input class='actionBtn' type='submit' id='confirm' name='confirm'
value='Confirm' onclick='genChanged();'/>
</td>
<td>
<input class='actionBtn' type='button' id='cancel' name='cancel'
value='Cancel' onclick='cancel();' />
</td>
</tr>
这是 cancel() 函数:
function cancel(){
alert('in cancel');
document.getElementById('editRow').hidden = false;
document.getElementById('actionRow').hidden = true;
window.location.replace("admin.php");
};
警报永远不会出现!
在一个表单中放置多个非提交按钮是否正确?
更新 我的表格看起来像这样:
<form action='save.php' method='POST' id='myForm'>
我已将行 document.getElementById('myForm').submit();
添加到 getChange( ); 函数,使按钮为:
<input class='actionBtn' type='button' id='confirm' name='confirm'
value='Confirm' onclick='genChanged();'/>
但是,cancel(); 函数仍然不起作用!
最佳答案
id 和函数名称不能使用相同的名称。
在我的示例中,'a' 具有相同的 id 和函数名称 test(),而 b 具有不同的 id 和函数名称 cancel()...cancel 工作正常,而 test 则不行。
<script>
function cancel(){
alert('in cancel');
};
function test(){
alert("in test")
};
</script>
<body>
<form action='save.php' method='POST' id='myForm'>
<tr id='actionRow' name='actionRow' hidden='hidden'>
<td>
<input class='actionBtn' type='button' id='test' name='a'
value='a' onclick='test();'/>
</td>
<td>
<input class='actionBtn' type='button' id='b' name='b'
value='b' onclick='cancel()' />
</td>
</tr>
</form>
</body>
有关更多信息,您可以查看这个有用的答案:https://stackoverflow.com/a/9160009/1318727
关于php - 一种表单中的常规按钮和提交按钮不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17800178/