Good day. There is a script that looks for the name of the chords in the text and writes them into the path to the pictures, but before that replaces the symbols of the chords that are not allowed in the path to the files. It is necessary to set the name of the chord in the value of the alt attribute before replacing the characters.

var regex = /([ACDEFGH][b#]?[m]?[\(]?(2|5|6|7|9|11|13|6\/9|7\-5|7\-9|7 \#5|7\#9|7\+5|7\+9|7b5|7b9|7sus2|7sus4|add2|add4|add9|aug|dim|dim 7|m\|maj7|m6|m7|m7b5|m9|m11|m13|maj|maj7|maj9|maj11|maj13|mb5|m|s us|sus2|sus4){0,2}(\/[AH])?(\))?)(?=\s|\.|\)|-|\/)/g; var chords = $('.pre').text().match(regex); // ΠΏΠΎΠ»ΡƒΡ‡Π°Π΅ΠΌ Π°ΠΊΠΊΠΎΡ€Π΄Ρ‹ // Ρ„ΠΎΡ€ΠΌΠΈΡ€ΡƒΠ΅ΠΌ массив Ρ‚ΠΎΠ»ΡŒΠΊΠΎ с ΡƒΠ½ΠΈΠΊΠ°Π»ΡŒΠ½Ρ‹ΠΌΠΈ chords = chords.filter(function(value, index, self) { return self.indexOf(value) === index; }); // замСняСм символы chords = chords .join(' ') .replace(/\+/g, 'p') .replace(/\-/g, 'z') .replace(/\#/g, 'w') .replace(/\//g, 's') .split(' '); var content = ''; // Ρ„ΠΎΡ€ΠΌΠΈΡ€ΡƒΠ΅ΠΌ строчку с изобраТСниями chords.forEach(function(value) { content += '<img src="assets/app/img/chords/' + value + '.png" class="chord" alt="'+ Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ Π°ΠΊΠΊΠΎΡ€Π΄Π° Π΄ΠΎ Π·Π°ΠΌΠ΅Π½Ρ‹ символов +'">'; }); $('.tab_chords').append(content); 
  • It is not clear what exactly you have difficulty. Please provide a minimal example of code that reproduces the problem. - Nick Volynkin ♦
  • Yes, please correct the title. It should contain a brief description of the nature of the problem (and not a request for help). - Nick Volynkin ♦
  • There is no problem in the code. It is now working, but my knowledge is only enough to bring in the alt chords in which the script has already replaced the characters. I need to output chords in alt before replacing characters. Thank. - Victor Victor

1 answer 1

 // замСняСм символы ΠΈ сохраняСм Ρ€Π΅Π·ΡƒΠ»ΡŒΡ‚Π°Ρ‚ Π² Π½ΠΎΠ²Ρ‹ΠΉ массив var titleChords = chords .join(' ') .replace(/\+/g, 'p') .replace(/\-/g, 'z') .replace(/\#/g, 'w') .replace(/\//g, 's') .split(' '); var content = ''; // Ρ„ΠΎΡ€ΠΌΠΈΡ€ΡƒΠ΅ΠΌ строчку с изобраТСниями // alt - Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ ΠΈΠ· массива chords // src - Π·Π½Π°Ρ‡Π΅Π½ΠΈΠ΅ ΠΈΠ· массива titleChords с ΡΠΎΠΎΡ‚Π²Π΅Ρ‚ΡΡ‚Π²ΡƒΡŽΡ‰ΠΈΠΌ индСксом chords.forEach(function(value, index) { content += '<img alt="' + value + '" src="/images/chords/' + titleChords[index] + '_0.gif" />'; }); 
  • Thank! Again you helped me)) - Victor Victor