我正在尝试编写一个计算一段文本中音节数量的函数,我知道它不会那么准确,它只是我目前需要的一个简单版本,它大致计算了音节的数量。
whenkeydown = function(max_length) {
$("#my_text").unbind().keyup(function() {
//check if the appropriate text area is being typed into
if (document.activeElement.id === "my_text") {
//get the data in the field
var text = $(this).val();
function countSyllables(words) {
console.log(words);
for (var z; z < words.length; z++) {
word = word[z].toLowerCase();
if(word.length <= 3) { return 1; }
word = word.replace(/(?:[^laeiouy]es|ed|[^laeiouy]e)$/, '');
word = word.replace(/^y/, '');
syllables = word.match(/[aeiouy]{1,2}/g).length;
syllableCount += syllabes
}
return syllableCount
}
var syllableCount = countSyllables(text)
$("#noOfSyllables").html("").html(syllableCount).css("color", "#F7860C"); //orange
我在(aptana/firefox)调试器中得到的错误是“TypeError: $(...).html(...).html(...).css is not a function”,这是否意味着我的函数确实什么都不退?