我有一个从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()。。。取消工作很好,测试不好。
<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