document.getElementById('link').onmouseover = show;
document.getElementById('link').onmouseout = hide;
function show() {
document.getElementById('ul1').style.display = 'block';
document.getElementById('link').style.background ='red';
};
function hide() {
document.getElementById('ul1').style.display = 'none';
document.getElementById('link').style.background = ' #f1f1f1';
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
尝试下show(),hide()?
你把JS代码放在节点后面,或是用onload=function(){},或放代码放在jquery的$(function(){})里面
你这个可能是元素节点没有获取到的原因,建议你打印下
console.log(document.getElementById('link'))
,看看能不能获取到该元素。