テキストの音節の数をカウントする関数を作成しようとしていますが、それほど正確ではないことはわかっています。現時点で必要なのは、音節の数を大まかにカウントする単純なバージョンです。
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 は関数ではありません」です。これは、関数が機能することを意味しますか?何も返さない?