使用普通的“ol vanilla javascript”选择类名时遇到一些问题:
var email = document.getElementsByClassName('email');
var phone = document.getElementsByClassName('phone');
// Hide phone by default
phone.style.display = "none";
function showContact() {
var dropdown = document.getElementById( "contact-select" ); // Get a reference to the dropdown (select) element
var selectedItemValue = dropdown.options[ dropdown.selectedIndex ].value; // use the dropdown reference to get the selected item's value
if ( selectedItemValue === "phone" ) {
email.style.display = "none";
phone.style.display = "block";
} else {
phone.style.display = "none";
email.style.display = "block";
}
}
每当我尝试调用其中一个变量时,都会不断收到未定义的错误。任何帮助将不胜感激。谢谢!