Я разрабатываю игру TicTacToe с тимелистом.
Хочу задать пользователю следующий вопрос.
<p>Would you like to configure the symbols you would want to play
with?</p>
<input type = "button" value = "Yes" class = "btn" name = "btn_yes"/>
<input type = "button" value = "No" class = "btn" name = "btn_no"/>
При нажатии кнопки «Да» я хочу отобразить текстовое поле. Кто-нибудь может мне помочь? Я новичок в этом.
<style>
#myDIV {
width: 100%;
padding: 50px 0;
text-align: center;
background-color: #000;
margin-top: 20px;
color:#fffff;
}
</style>
<body>
<button onclick = "myFunction()">Yes</button>
<div id = "myDIV">
Can someone please help me?
</div>
<script>
function myFunction() {
var x = document.getElementById("myDIV");
if (x.style.display === "none") {
x.style.display = "block";
} else {
x.style.display = "none";
}
}
</script>
</body>
HTML
<html>
<head>
</head>
<body>
<p>Would you like to play a game</p>
<input type = "button" value = "Yes" class = "btn" name = "btn_yes" onclick = "btnClickYes()"/>
<input type = "button" value = "No" class = "btn" name = "btn_no"/>
</body>
</html>
JS
var amount = 0;
function btnClickYes() {
amount += 1;
if (amount == 1){
var textbox = document.createElement('input');
textbox.type = 'text';
document.body.appendChild(textbox);
amount = 1;
}
};
вы можете добиться этого с помощью события javascript onclick