[英]Get the value of a submit button to be a condition for alert message in JavaScript
我想從將是警報“ functionwiningcombinations()”消息的函數中獲取要提交的提交按鈕的值。
這是我的腳本:
<!DOCTYPE html>
<html>
<body>
<script>
var nextTurn = 'X'
function chose1() {
if (document.getElementById("Button1").click = true) {
if (document.getElementById('Button1').value == "") {
document.getElementById('Button1').value = nextTurn;
document.getElementById('Button1').style.fontSize = "30px";
document.getElementById('Button1').style.color = 'Blue';
if (document.getElementById('Button1').value == "O") {
document.getElementById('Button1').style.color = 'Red'
}
changeTurn();
}
}
}
function winningcombinations() {
if (document.getElementById('Button1').value == "X" ) {
alert("Congratulations X you won!!");
}
}
</script>
這是我正在使用的9個按鈕之一:
<input id="Button1" style="width: 100px; text-align:center; height: 100px;" type="button" value="" onclick="chose1()"/></td>
</tr>
</table>
</body>
</html>
你可以試試看 通過onclick本身傳遞值使用this.value
<input id="Button1" style="width: 100px; text-align:center; height:100px;"type="button" value="X" onclick="chose1(this.value)"/></td>
在JavaScript中
function chose1(bval1) {
//write your code here
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.