0

如果 document.result.word.value 不是变量,则它可以正常工作,但是一旦我将其设为变量,它就会给出诸如“inputWord.charAt 不是函数”之类的错误

$(document).ready(function() {
$("#submit").click(function() {
    var amountOfLetters = 0;
    var inputWord = document.result.word.value.toLowerCase;
    for(i=0;i<5;i++) {
        var letter = inputWord.charAt(i);
        var counter = compWord.indexOf(letter);
        if(counter > -1) {
            amountOfLetters++;
        }
    }
    var isValidWord = 0;
    for(var i = 0; i < 8939; i++) {
        if(inputWord == library[i]) {
            isValidWord = 1;
            break;
        };
    };
    if(isValidWord == 0) {
        alert("You cannot use that word");
        $('#getWord').val('');
    } else {
        $(".left").append("<p id='list'>" + inputWord + "(" + amountOfLetters + ")" + "</p>");
        var compChoice = library[Math.floor((Math.random() * 8938) + 1)];
        $(".right").append("<p id='list'>" + compChoice + "</p>");
        $('#getWord').val('');
    };
});

});

4

1 回答 1

2

toLowerCase方法,试着这样称呼它:

 var inputWord = document.result.word.value.toLowerCase();
于 2013-08-04T05:34:23.537 回答