如何找出单击了哪个按钮。
`<input type="submit" name="quest" id="ques" value="quest" />
<input type="submit" name="answer" id="ans" value="answer" />`
如何找出单击了哪个按钮。
`<input type="submit" name="quest" id="ques" value="quest" />
<input type="submit" name="answer" id="ans" value="answer" />`
很容易你可以像我一样编码
代码:
<html>
<head>
<script language="javascript">
function checkBtn(event) {
alert(event.target.name);
}
</script>
</head>
<body>
<br /><br />
<form action="multiSubmit.php" method="post" onSubmit="return false;">
<input type="submit" name="quest" id="quest" value="quest" onClick="checkBtn(event)" /><br />
<input type="submit" name="answer" id="answer" value="answer" onClick="checkBtn(event)" /><br />
</form>
</body>
</html>
代码应如下所示
<script language="javascript">
function checkBtn(event) {
alert(event.target.name);
}
</script>
onClick="checkBtn(event)"
为您的每个按钮添加一个。否则,您可以onsubmit
像这样在表单中添加onSubmit="checkBtn(event)"