1
У меня возникла проблема с преобразованием кода из JavaScript в jQuery. Это пример кода из W3Schools, чтобы создать кнопку выпадающего списка.Преобразование с JavaScript в
// Get the button, and when the user clicks on it, execute myFunction
document.getElementById("myBtn").onclick = function() {myFunction()};
/* myFunction toggles between adding and removing the show class, which is used to hide and show the dropdown content */
function myFunction() {
document.getElementById("myDropdown").classList.toggle("show");
}
// Close the dropdown if the user clicks outside of it
window.onclick = function(event) {
if (!event.target.matches('.dropbtn')) {
var dropdowns = document.getElementsByClassName("dropdown-content");
var i;
for (i = 0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
}
}
Загрузите это для скрипки –
@ AleksandarĐokić Имеется опция фрагмента. Пожалуйста, продвигайте это. –