web蓝桥杯真题:冰墩墩心情刻度尺

代码:

javascript 复制代码
// TODO: 待补充代码
BingDunDun.className='BingDunDun not-satisfied'
range.onchange = (e) => {
  let value = Number(e.target.value); // value 进度条的值
  // TODO: 待补充代码
  if(value == 25) {
    BingDunDun.className='BingDunDun a-little-unsatisfied'
  } else if(value == 50) {
    BingDunDun.className='BingDunDun ordinary'
  } else if(value == 75) {
    BingDunDun.className='BingDunDun satisfied'
  } else if(value == 100) {
    BingDunDun.className='BingDunDun great'
  } else {
    BingDunDun.className='BingDunDun not-satisfied'
  }
};

考察:

元素添加类名:element.className='class1 class2'

此外,

行内样式操作:element.style.width = '250px'

给元素添加样式:element.classList.add(newClassName)

给元素移除样式:element.classList.remove(oldClassName)

className和classList.add的区别:

前者是直接替换原来的类名,后者是在原类名基础上再加一个类名

相关推荐
SoaringHeart1 小时前
Flutter进阶:用OverlayEntry 实现所有弹窗效果
前端·flutter
IT_陈寒3 小时前
Vite静态资源加载把我坑惨了
前端·人工智能·后端
herinspace3 小时前
管家婆实用贴-如何分离和附加数据库
开发语言·前端·javascript·数据库·语音识别
小码哥_常3 小时前
从MVC到MVI:一文吃透架构模式进化史
前端
嗷o嗷o3 小时前
Android BLE 的 notify 和 indicate 到底有什么区别
前端
豹哥学前端4 小时前
别再背“var 提升,let/const 不提升”了:揭开暂时性死区的真实面目
前端·面试
lar_slw4 小时前
k8s部署前端项目
前端·容器·kubernetes
拉拉肥_King4 小时前
Ant Design Table 横向滚动条神秘消失?我是如何一步步找到真凶的
前端·javascript
GreenTea4 小时前
DeepSeek-V4 技术报告深度分析:基础研究创新全景
前端·人工智能·后端
河阿里5 小时前
HTML5标准完全教学手册
前端·html·html5