扫码关注官方订阅号
这里要实现的是class 的增和删。比如
请给出你的测试用例。
这是作死的节奏呀,className 不应该这么搞吧。
// remove two document.getElementById('p').classList.remove('two'); // remove two document.getElementById('p').classList.add('two');
<style type="text/css"> .one { color: red; } .two { border: 1px solid blue; } </style> <script type="text/javascript"> setTimeout(function(){ var o = document.getElementsByTagName('p')[0]; function fnRemoveClass(e,s){ if (Object.prototype.toString.call(e).indexOf('HTML') === -1 || typeof s !== 'string') return; var re = new RegExp('(\\b|^)' + s + '(\\s|$)','g'); console.log(e.className = e.className.replace(re,'')); } fnRemoveClass(o,'two'); },0); </script> <p class="one two">demo</p>
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
请给出你的测试用例。
这是作死的节奏呀,className 不应该这么搞吧。