php如何修改css属性?

2020-08-12 22:02:54

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

php修改css属性的方法:

在PHP代码中,设置如下变量:

<?php$state = 'block';?><html>    <script>        var state = "<?=$state?>";    </script></html>

基本上,您将PHP变量输出到您的文件,然后使用全局javascript变量来保存该变量的值.在您的Jquery代码中,您将能够读取此变量.

我在我的框架中使用了更加模块化的版本,我的渲染引擎能够控制要加载的CSS或JS文件.还有一个由我的脚本生成的全局javascript对象,它包含所有全局数据,如基本URL,服务器时区,同步数据等,这些数据将在所有客户端脚本中重用.

希望这可以帮助.

更新:

以下是它的工作原理:

// 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
相关文章 大家在看