I want to check if $('#td1').text() === “x”?

后端 未结 5 1340
余生分开走
余生分开走 2021-01-28 16:10

I want to check if innerHtml have X or O , so i can not add again any thing else , but it\'s not working . it stop after adding the check code , I\'m trying here to do a simple

5条回答
  •  北恋
    北恋 (楼主)
    2021-01-28 16:46

    There is quite a few things wrong with your code,

    I suggest you take a look at this quick hack I put together which is working, feel free to ask questions.

    http://jsfiddle.net/blowsie/TKq2H/4/

    function call() {
        var x = Math.floor((Math.random() * 9) + 1);
        if ($('#td' + x).text() === "x" || $('#td' + x).text() == "o") {
            call();
        }
        else {
            $("#td" + x).text("o");
        }
    
    }
    $('td').click(function() {
        var no = $(this).data('no')
        if ($('#td' + no).text() === "x" || $('#td' + no).text() == "o") return false;
        else {
            $("#td" + no).text("x");
            call();
        }
    });​
    
    
    

    " X ,O Game "

提交回复
热议问题