函数适用于除= <ie8之外的所有浏览器

Jua*_*les 2 javascript jquery

我的功能适用于所有浏览器,除了ie8及以下.任何人都可以告诉我问题是什么,可能如何解决它?谢谢!

var match;
var chords = 
['C','C#','D','D#','E','F','F#','G','G#','A','A#','B','C','Db','D','Eb','E','F','Gb','G','Ab','A','Bb','B','C'];
var chords2 = 
['C','Db','D','Eb','E','F','Gb','G','Ab','A','Bb','B','C','C#','D','D#','E','F','F#','G','G#','A','A#','C'];
var chordRegex = /C#|D#|F#|G#|A#|Db|Eb|Gb|Ab|Bb|C|D|E|F|G|A|B/g;

function transposeUp(x) {
    $('.chord'+x).each(function(){
        ///// initializes variables /////
        var currentChord = $(this).text(); // gatheres each object
        var output = "";
        var parts = currentChord.split(chordRegex);
        var index = 0;
        /////////////////////////////////
        while (match = chordRegex.exec(currentChord)){
            var chordIndex = chords.indexOf(match[0]);
            output += parts[index++] + chords[chordIndex+1];
        }
        output += parts[index];
        $(this).text(output);
    });
}

function transposeDown(x){
$('.chord'+x).each(function(){
    var currentChord = $(this).text(); // gatheres each object
    var output = "";
    var parts = currentChord.split(chordRegex);
    var index = 0;
    while (match = chordRegex.exec(currentChord)){
        var chordIndex = chords2.indexOf(match[0],1);
        output += parts[index++] + chords2[chordIndex-1];
    }
    output += parts[index];
    $(this).text(output);
});
}
Run Code Online (Sandbox Code Playgroud)

编辑

我刚刚发现它也与split方法有关.我无法解决这个问题.indexOf原型现在可以工作了,但是这个函数仍然没有工作,但是我得到一个错误,说chordRegex不是一个对象.由于某种原因,它无法正常工作.