我无法弄清楚如何在一个函数和另一个函数中同时调用参数。我可以从一个不同的函数调用一个函数而没有任何问题,但添加额外的参数是我迷路的地方。
这是我迄今为止所尝试的内容: https://jsfiddle.net/Realto619/7fgt2za2/1/
var G = [3, 2, 0, 0, 3, 3];
var Gm = [33, 3, 3, 33, 33, 33];
var Em = [0, 2, 2, 0, 0, 0];
function setChord(str6, str5, str4, str3, str2, str1) {
var domPath = 'http://chords.netcentrx.net/img/halfsize/f';
var setFrets = ' <div class="fretboard">\n' +
' <img class="str6" src="' + domPath + str6 + '.png" />\n' +
' <img class="str5" src="' + domPath + str5 + '.png" />\n' +
' <img class="str4" src="' + domPath + str4 + '.png" />\n' +
' <img class="str3" src="' + domPath + str3 + '.png" />\n' +
' <img class="str2" src="' + domPath + str2 + '.png" />\n' +
' <img class="str1" src="' + domPath + str1 + '.png" />\n' +
' </div>\n';
return setFrets;
}
function testChord(chordName) {
var myObject = setChord.apply(myObject, chordName);
$('body').append(myObject);
}
testChord(Gm);
testChord(G);
// it works up thru here, but then fails miserably...
function testChord2(divID, chordDesc, chordName) {
var setChordDiv = '<div class="chord" id="' + divID + '">\n' +
' <div class="chord">\n' +
' <div class="chordName">' + chordDesc + '</div>';
return setChordDiv;
var myObject = setChord.apply(myObject, chordName);
var setChordDiv2 = ' </div>'+
' </div>'+
'</div>';
return setChordDiv2;
$('body').append(setChordDiv+myObject+setChordDiv2);
}
testChord2('Gm1','Gm', Gm);
有人能引导我回到救赎之路吗?
提前致谢,
保