如何找出哪個按鈕被點擊。要找到哪個按鈕被點擊javascript php
`<input type="submit" name="quest" id="ques" value="quest" />
<input type="submit" name="answer" id="ans" value="answer" />`
如何找出哪個按鈕被點擊。要找到哪個按鈕被點擊javascript php
`<input type="submit" name="quest" id="ques" value="quest" />
<input type="submit" name="answer" id="ans" value="answer" />`
下面的代碼是按鈕被點擊這對於檢查的解決方案。
document.getElementById('button').onclick = function() {
alert("button was clicked");
};
代碼應該如下
<script language="javascript">
function checkBtn(event) {
alert(event.target.name);
}
</script>
添加onClick="checkBtn(event)"
您的每一個按鈕。否則,你可以一個onsubmit
添加到您的表單如onSubmit="checkBtn(event)"
它很容易,你可以編寫像我一樣
代碼:
<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>
它不是嘰嘰喳喳,你可以去超過160個字符.. – Shurmajee
按照鏈接答案:http://stackoverflow.com/questions/6973139/php-which-button-is-clicked –