方法:1、用attr()将class属性的值设为空,语法“$(selector).attr(class,)”;2、用removeAttr()移除class属性,语法“$(selector).removeAttr(class)”。
本教程操作环境:windows7系统、jquery1.10.2版本、Dell G3电脑。
使用attr()将元素中class属性的值设为空
语法:
$(selector).attr(class,)
使用removeAttr()移除元素中的class属性
语法:
$(selector).removeAttr(class)
示例:
<!DOCTYPE html> <html> <head> <Meta charset=utf-8> <script src=js/jquery-1.10.2.min.js></script> <script> $(document).ready(function() { $(button).click(function() { $(.Box1).attr(class, ); $(.Box2).removeAttr(class); }); }); </script> <style> div { border: 1px solid red; margin: 10px; } .Box1 { background-color: #FFC0CB; } .Box2 { background-color: green; color: white; } </style> </head> <body> <div class=Box1>测试文本</div> <div class=Box2>测试文本</div> <br> <button>去掉class属性</button> </body> </html>
相关视频教程推荐:jQuery视频教程
原文地址:https://www.jb51.cc/js/1203716.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。