我正在尝试使用 Javascript 在单个页面上删除某个元素 (#main-content) 的类。该页面是用 PHP 编写的,但据我所知,Javascript 是删除该类的最简单方法。我引用了帖子:How can I insert javascript in php?和 RemoveClass AddClass When Page Load帮助我提出以下解决方案:
<? php echo '<script type=\"text/javascript\">
$(document).ready(function() {
$(\"section#main-content\").removeClass(\"trans-header\");
});</script>';
?>
我验证了这段代码并将其放在我的页面顶部,但它似乎不起作用。我可能会错过什么? (另外,如果有帮助,这是我尝试将代码应用到的页面:http://7a9.007.myftpupload.com/contact/)
最佳答案
请改用它,您不需要 jQuery。并将其添加到 <head></head>
中的某处或在 <body></body>
内- 不高于 html
就像现在一样。
<?php echo '<script>document.getElementById("main-content").classList.remove("trans-header");</script>' ?>
关于javascript - 在 PHP 中使用 Javascript 删除类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44102855/