<div id="dn">我是要显示或隐藏的元素</div>
<script>
function handleWindowResize() {
var element = document.getElementById('dn');
var windowWidth = window.innerWidth;
if (windowWidth > 900) {
element.style.display = 'block'; // 显示元素
} else {
element.style.display = 'none'; // 隐藏元素
}
}
// 初始加载时和窗口尺寸改变时触发判断
window.addEventListener('load', handleWindowResize);
window.addEventListener('resize', handleWindowResize);
</script>