Подсказки с городами не работают (автокомплит): <!DOCTYPE html> <html> <head> <title><%=…
- User
Подсказки с городами не работают (автокомплит):
<script>const modal = document.getElementById("edit-profile-modal"); const btn = document.getElementsByTagName("a")[0]; const span = document.getElementsByClassName("close")[0];
btn.onclick = function() { modal.style.display = "block"; } span.onclick = function() { modal.style.display = "none"; } window.onclick = function(event) { if (event.target == modal) { modal.style.display = "none"; } } //скрыть плеер, если ссылка не внесена const song1Input = document.getElementById("soundcloud");const song2Input = document.getElementById("soundcloud1"); const player1 = document.getElementsByTagName('iframe')[0]; const player2 = document.getElementsByTagName('iframe')[1]; let songs = { song: "", song1: "" }
function hidePlayer(player) { player.src = ""; player.style.display = "none"; }
function updateSongs() { songs.song = song1Input.value.trim(); songs.song1 = song2Input.value.trim(); }
function updatePlayers() { if (songs.song !== "") { player1.src =
https://w.soundcloud.com/player/?url=${songs.song}&color=%23ff5500&auto_play=false&hide_related=false&show_comments=true&show_user=true&show_reposts=false&show_teaser=true&visual=true; player1.style.display = "block"; } else { hidePlayer(player1); }if (songs.song1 !== "") { player2.src =
https://w.soundcloud.com/player/?url=${songs.song1}&color=%23ff5500&auto_play=false&hide_related=false&show_comments=true&show_user=true&show_reposts=false&show_teaser=true&visual=true; player2.style.display = "block"; } else { hidePlayer(player2); } }song1Input.addEventListener("input", function() { updateSongs(); updatePlayers(); });
song2Input.addEventListener("input", function() { updateSongs(); updatePlayers(); });
updateSongs(); updatePlayers(); //Валидация ссылок с soundcloud function updatePlayers() { if (isValidSoundcloudUrl(songs.song)) { player1.src =
https://w.soundcloud.com/player/?url=${songs.song}&color=%23ff5500&auto_play=false&hide_related=false&show_comments=true&show_user=true&show_reposts=false&show_teaser=true&visual=true; player1.style.display = "block"; } else { hidePlayer(player1); }if (isValidSoundcloudUrl(songs.song1)) { player2.src =
https://w.soundcloud.com/player/?url=${songs.song1}&color=%23ff5500&auto_play=false&hide_related=false&show_comments=true&show_user=true&show_reposts=false&show_teaser=true&visual=true; player2.style.display = "block"; } else { hidePlayer(player2); } }function isValidSoundcloudUrl(url) { const regex = /^https?://(soundcloud.com|snd.sc)/(.*)$/; return regex.test(url); }
<script> $("#city").autocomplete({ source: '/autocomplete/cities', minLength: 1,});
- Assistant
I suggest to change the
$('#city').autocomplete({part from script tag to a separate script file and then add a listener for the DOMContentLoaded event. Here's how you can modify the code:-
Create a new file named
autocomplete.jsin your project's JavaScript folder (e. js/autocomplete.js). -
Put the following code in the
autocomplete.jsfile:
document.addEventListener("DOMContentLoaded", function() { $("#city").autocomplete({ source: '/autocomplete/cities', minLength: 1 }); });- In your HTML file, replace the inline script tag with the shown below:
<script src="/js/autocomplete.js"></script>This modification will make sure that the autocomplete functionality loads when the DOM is completely loaded.
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.