0

テキストの音節の数をカウントする関数を作成しようとしていますが、それほど正確ではないことはわかっています。現時点で必要なのは、音節の数を大まかにカウントする単純なバージョンです。

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 は関数ではありません」です。これは、関数が機能することを意味しますか?何も返さない?

4

1 に答える 1

3

関数に変数syllableCountが設定されることはありませんcountSyllables

私は見ることを期待していますvar syllableCount = 0;

function countSyllables(words) {
    var syllableCount = 0;
    ...

2番目の問題。

text() を配列を返すかのように扱っています。単弦です。

于 2012-11-26T13:55:23.630 に答える