Please tell me how to modify the code.

Asked 2 years ago, Updated 2 years ago, 35 views

<!DOCTYPE html>
<html lang="ja">
<head>
    <metacharset="UTF-8"/>
    <title>tekisutogataRPG</title>

<style>
.cell {width:80px;
    height —80px;
    background-color:skyblue;
    font-size: 40pt;
    margin:0 auto;}
</style>

<script>
var counter;
function makeBoard(){
    vari,j;
    var cells="";
    counter = 0;
    for(i=0;i<3;i=i+1){
        for(j=0;j<3;j=j+1){
            cells=cells+"<button class='cell'id='c'+i+j+'onClick='counter=counter+1;changeCell("+i+","+j+");'> &</button>";

        }
        cells=cells+"<br>";
    }
    document.getElementById("board").innerHTML=cells;
    document.getElementById("count").innerHTML = "Workaround:"+counter;
}
function changeCell(x,y){
    if(counter==9) { document.getElementById("c"+x+y).innerHTML="right";}
    else { document.getElementById("c"+x+y).innerHTML="wrong";}
    document.getElementById("count").innerHTML = "Workaround:"+counter;
}
</script>

</head>

<body>
<divid="board"></div>
<script>
makeBoard();
</script>
<button onClick="makeBoard();">riset</button>
<divid="count"></div>
</body>
</html>

Please tell me how to change the board surface to an image when you press the board surface.
Also, please tell me how to change the button on the board when the counter reaches 9.

javascript html css

2022-09-29 21:41

1 Answers

Simply

 document.getElementById("c"+x+y).innerHTML="...";

This is

 document.getElementById("c"+x+y).innerHTML='<img src="url of image"/>";

inserts the img element.For more information, I think you should study using the keyword DOM operation.


2022-09-29 21:41

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.