class里面定义的display属性无法通过js改变

class里面定义的display属性无法通过js改变,非常郁闷的问题,以前遇到过一次,这次有忘记了,调试了n久才想起来。

自己在元素上定义style="display:none" 用js可以动态改变,但是如果把display属性定义到class里面就不行了。

同时定义也不行,如:<div id="note_list_div" class="note_list_div" style="display:none;"></div>

.note_list_div{display:none;width:100%;clear:both;}

 

按照标准应该是元素上的style优先级高于class的,在js控制的时候就不起作用了,浏览器不按标准行事经常出现非常理的bug真是郁闷啊。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
是的,您说得对。下面是一个简单的样式表和JavaScript脚本,您可以将它们分别保存为`style.css`和`script.js`文件,并与HTML代码一起放在同一目录下。 样式表`style.css`: ``` /* 导航样式 */ nav { background-color: #333; color: #fff; } nav ul { list-style: none; margin: 0; padding: 0; } nav li { display: inline-block; margin-right: 10px; } nav a { color: #fff; text-decoration: none; padding: 5px; } nav a:hover { background-color: #555; } /* 浮窗样式 */ .floating-box { position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); background-color: #fff; padding: 20px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.5); } .floating-box h2 { margin-top: 0; } /* 新闻轮播样式 */ .news-carousel { margin-top: 20px; position: relative; } .news-carousel h2 { margin-top: 0; } .carousel-item { position: absolute; top: 0; left: 0; opacity: 0; transition: opacity 0.5s ease-in-out; } .carousel-item.active { opacity: 1; } .carousel-item img { width: 100%; height: auto; } .carousel-item h3 { margin-top: 0; margin-bottom: 5px; } .carousel-item p { margin-top: 0; } ``` JavaScript脚本`script.js`: ``` // 获取新闻轮播容器和轮播项 var carousel = document.querySelector('.news-carousel'); var items = carousel.querySelectorAll('.carousel-item'); // 初始化轮播项 var currentItemIndex = 0; items[currentItemIndex].classList.add('active'); // 定时切换轮播项 setInterval(function() { // 隐藏当前轮播项 items[currentItemIndex].classList.remove('active'); // 移动到下一个轮播项 currentItemIndex++; if (currentItemIndex >= items.length) { currentItemIndex = 0; } // 显示下一个轮播项 items[currentItemIndex].classList.add('active'); }, 5000); ``` 该样式表定义了导航、浮窗和新闻轮播的样式,包括背景颜色、字体颜色、间距、字体大小等。该JavaScript脚本用于轮播新闻条目,每隔5秒自动切换到下一个条目。您可以根据自己的需求修改样式和脚本。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值