当前位置:Gxlcms > PHP教程 > php动态加载JavaScript或css文件的方法

php动态加载JavaScript或css文件的方法

时间:2021-07-01 10:21:17 帮助过:1人阅读

test6.php

  1. header('Content-Type: application/x-javascript; charset=UTF-8');
  2. $str = $_GET["str"];
  3. ?>
  4. // javascript document
  5. // by bbs.it-home.org
  6. alert('');
  7. function tester(string)
  8. {
  9. string ? alert(string) : alert('you call a function named tester');
  10. }
  11. ?>

第二种方法: test.php

test5.php

  1. var value="this is value.";

加载多JavaScript文件的实例:

  1. var url = [
  2. 'ajax.php?ajax=1',
  3. 'functions.js'
  4. ];
  5. loadmultijs(url,function(){ alert("加载完毕。"); /* 这里可以调用动态加载的JS文件的数据或方法 */ });

2. 动态加载css文件 test.php

  1. this document has a #e4e4e4 background, a 300px/400px div, and a arial/24px/red words.

div.php

  1. // declare the output of the file as CSS
  2. header('Content-type: text/css');
  3. // include the script
  4. //include('others.php');
  5. $width = $_GET['w'];
  6. $height = $_GET['h'];
  7. ?>
  1. div{width:px;height:px;border:blue 1px solid;}

fonts.php

  1. // declare the output of the file as CSS
  2. header('Content-type: text/css');
  3. // include the script
  4. //include('others.php');
  5. $size = $_GET['s'];
  6. $color = $_GET['c'];
  7. ?>
  8. body{font-family:arial;font-size:px;color:}

就是这些了,php动态加载js与css的方法就介绍完了,建议大家亲自动手测试下,看看具体的实现有没有问题。

人气教程排行