php修改css属性的方法:首先将PHP变量输出到相应的文件;然后使用全局javascript变量来保存该变量的值;最后在Jquery代码中查找,将能够读取此变量。

在PHP代码中,设置如下变量:
<?php
$state = 'block';?><html>
<script>
var state = "<?=$state?>";
</script></html>基本上,您将PHP变量输出到您的文件,然后使用全局javascript变量来保存该变量的值.在您的Jquery代码中,您将能够读取此变量.
我在我的框架中使用了更加模块化的版本,我的渲染引擎能够控制要加载的CSS或JS文件.还有一个由我的脚本生成的全局javascript对象,它包含所有全局数据,如基本URL,服务器时区,同步数据等,这些数据将在所有客户端脚本中重用.
立即学习“PHP免费学习笔记(深入)”;
希望这可以帮助.
更新:
以下是它的工作原理:
// In your html file <script>var a = '<?=$state?>';</script> <-- set the global var here <script src="js/bar.js"></script> <-- include your scripts after the global one -------------------------------------------------------- // In your bar.js file alert(a) // should show the contents of $state stored in the global var a
相关学习推荐:PHP编程从入门到精通
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号