登录  /  注册
博主信息
博文 43
粉丝 0
评论 3
访问量 34835
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
1. 实例演示classList对象 2. 使用blur事件进行表单非空验证
Time
原创
481人浏览过

classList对象

示例代码:

  1. <style>
  2. .box {
  3. background-color: yellow;
  4. color: red;
  5. }
  6. .active {
  7. border: 1px solid #333;
  8. }
  9. .em {
  10. background-color: rgb(0, 238, 255);
  11. color: rgb(255, 0, 34);
  12. }
  13. .bgc {
  14. background-color: greenyellow;
  15. }
  16. </style>
  17. </head>
  18. <body>
  19. <div class="box">php中文网</div>
  20. <script>
  21. let box = document.querySelector(".box");
  22. console.log(box);
  23. //添加class
  24. box.classList.add("active");
  25. //判断是否有class
  26. console.log(box.classList.contains("box"));
  27. //替换class
  28. box.classList.replace("box", "em");
  29. //移除class
  30. box.classList.remove("em");
  31. //toggle 有去无加
  32. box.classList.toggle("bgc");
  33. </script>

blur事件进行表单非空验证

示例代码:

  1. //焦点移除密码不能为空
  2. document.forms.login.password.onblur = function () {
  3. if (this.value.length === 0) {
  4. alert("密码不能为空");
  5. return false;
  6. }
  7. };
批改老师:PHPzPHPz

批改状态:合格

老师批语:
本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
0条评论
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号

  • 登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学