-
-
test6.php
- header('Content-Type: application/x-javascript; charset=UTF-8');
- $str = $_GET["str"];
- ?>
-
- // javascript document
- // by bbs.it-home.org
- alert('');
-
- function tester(string)
- {
- string ? alert(string) : alert('you call a function named tester');
- }
- ?>
第二种方法:
test.php
-
test5.php
- var value="this is value.";
加载多JavaScript文件的实例:
- var url = [
- 'ajax.php?ajax=1',
- 'functions.js'
- ];
- loadmultijs(url,function(){ alert("加载完毕。"); /* 这里可以调用动态加载的JS文件的数据或方法 */ });
2. 动态加载css文件
test.php
-
-
-
-
-
-
- this document has a #e4e4e4 background, a 300px/400px div, and a arial/24px/red words.
-
-
div.php
- // declare the output of the file as CSS
- header('Content-type: text/css');
-
- // include the script
- //include('others.php');
-
- $width = $_GET['w'];
- $height = $_GET['h'];
- ?>
-
- div{width:=$width?>px;height:=$height?>px;border:blue 1px solid;}
fonts.php
- // declare the output of the file as CSS
- header('Content-type: text/css');
-
- // include the script
- //include('others.php');
-
- $size = $_GET['s'];
- $color = $_GET['c'];
- ?>
- body{font-family:arial;font-size:=$size?>px;color:=$color?>}
就是这些了,php动态加载js与css的方法就介绍完了,建议大家亲自动手测试下,看看具体的实现有没有问题。 |