抱歉,我对 JS 很陌生,我正在尝试编写一些代码来动态计算页面上的单词,这段代码在“whenkeydown”函数中:
var text = $(this).val();
var word=text.split(" ")
//word counter
function countWords(word, text) {
var y = word.value;
var words = 0;
a = y.replace(/\s/g, ' ');
a = a.split(' ');
for ( z = 0; z < a.length; z++) {
if (a[z].length > 0)
words++;
}
wordCount = words;
}
但是我在调试器中收到一条错误消息,说“TypeError:y is undefined”?谢谢