Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/434.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 函数在除=<;ie8_Javascript_Jquery - Fatal编程技术网

Javascript 函数在除=<;ie8

Javascript 函数在除=<;ie8,javascript,jquery,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'

我的功能适用于除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);
});
}
编辑

我刚刚发现它也与split方法有关。我就是修不好。indexOf原型现在可以工作了,但是这个函数仍然不能工作,但是我得到一个错误,说chordRegex不是一个对象。由于某些原因,它无法工作。

IE8不支持。您必须导入一个或编写自己的

见:


如果您已经在使用jquery,则应该使用该函数,而不是
索引的

欢迎使用web开发。:)+1这正是我想要的,但我如何将其实现到我的功能中?如果你不介意的话。。。谢谢那么,只需将问题顶部的代码添加到JS的顶部即可。它在IE8的阵列原型中添加了一个
indexOf
方法。但是,既然您已经在使用jQuery,我会考虑查看<代码> $.InActual。请原谅,我是javascript和jquery的新手。我把它贴在上面,但还是没有运气@你有什么想法吗,也许是小提琴@卡里姆79谢谢你的帮助,但我刚刚发现这只是我的问题之一。这些函数还有其他方面。我有一个错误,说chordRegex不是一个对象,还有其他想法吗?谢谢你给我指引了正确的方向,但是split方法也有问题,所以我不得不重写这个方法。好吧,你试错了。替换
和弦.indexOf(匹配[0])
$.inArray(匹配[0],和弦))。我这样做了,它适用于transposeUp函数,但仍然不适用于ie8及以下版本。对于transposeDown,它在任何浏览器中都不起作用。