All articles(网络文学目录) All Pictures(图片目录) All Softwares(软件目录)

 
php+javascript 静态化简单实例_[PHP教程]

Writer: 归海一刀 Article type: Programming skills(编程技巧) Time: 2014/2/17 7:13:44 Browse times: 377 Comment times: 0

php+javascript 静态化简单实例_[PHP教程]


Head photo

Go homepage
Upload pictures
Write articles

php+javascript 静态化简单实例_[PHP教程] 1. php生成js文件:

a=array(
array('title'=>'本地新闻1',ln=>'#'),
array('title'=>'本地新闻2',ln=>'#'),
array('title'=>'本地新闻3',ln=>'#')

);//实际操作中可通过数据库得到记录集数组
news=' var a=['; //把该数组转化为javascrīpt形式

for(i=0;i

if(i==count(a)-1) {
news.='{'
."title:'"
.a[i][title]."'"
.","
."ln:'"
.a[i][ln]
.'\'}';
}else {
news.='{'
."title:'"
.a[i][title]."'"
.","
."ln:'"
.a[i][ln]
.'\'},'; //如不是最后一个数据,则用逗号隔开,否则结束
}
}

news.='];';
fh=fopen("file.js","w");
fwrite(fh,news);
fclose(fh); //写入js
?>

2.html 文件





无标题文档




//定义显示的格式,先通过display:none 隐藏


title



//引用js




news_obj=document.getElementById('news');
e=news_obj.innerHTML;
re=/\title/g; //正则,匹配title
re2=/\link/g; // 匹配link
for(i=0;i tmp=e.replace(re,a[i].title); //用a[i].title代替取出的title
tmp=tmp.replace(re2,a[i].ln);
document.write(tmp); //显示文本
}









There are 0 records,
Comment:
Must be registered users to comment(必须是注册用户才能发表评论)

Disclaimer Privacy Policy About us Site Map
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.