当前位置: 首页 > 图文教程 > 网络编程 > Javascript > JavaScript静态的动态

Javascript
form中限制文本字节数js代码
use jscript with List Proxy Server Information
use jscript List Installed Software
List Installed Software Features
List Information About the Binary Files Used by an Application
List the Codec Files on a Computer
List the UTC Time on a Computer
List Installed Hot Fixes
excel操作之Add Data to a Spreadsheet Cell
Add Formatted Data to a Spreadsheet
Apply an AutoFormat to an Excel Spreadsheet
JavaScript语法着色引擎(demo及打包文件下载)
类之Prototype.js学习
一款JavaScript压缩工具:X2JSCompactor
iis6+javascript Add an Extension File
jscript之Open an Excel Spreadsheet
jscript之Read an Excel Spreadsheet
jscript之List Excel Color Values
去除图像或链接黑眼圈的两种方法总结
Add a Formatted Table to a Word Document

Javascript 中的 JavaScript静态的动态


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-12   浏览: 152 ::
收藏到网摘: n/a

这段时间因为要做个网站,而空间又不支持ASP,所以又拿起JavaScript教程看了下,看能不能在静态的空间里实现动态,当然,这个动态不是真正意义上的了,可以说只是一个“伪动态”了:)
最基本的动态页面的功能,莫过于news.asp?id=1这样的形式了,于是我就拿这个目标开工,弄了一会还真有些成效~基本构思是:从浏览器的地址栏获取当前文件的地址,然后从其中提取id,最后用内嵌框架来显示相关内容。以下是基本的代码
复制代码 代码如下:

<script>
var str,len,pos,id,fn; // 定义一些变量
str=top.window.location.href; //获取当然文件地址
len=str.length; // 得到地址长度
pos=str.indexOf("?id=",0); // 得到"?id="的起始地址
if(pos>0) // 判断是否存在"?id="
{
id=str.substring(pos+4,len); // 获取ID
fn="<iframe src='news/" + id + ".htm'></iframe>" // 在内嵌框架里显示相关内容
document.write(fn); // 输出
}
else
{
document.writeln("错误的参数!"); // 不存在ID
}
</script>

这样,就可以把新闻做成页面放在news目录,然后在外部调用news.htm?id=1就可以来查看相关的新闻了~~当然这里的代码并不成熟,比如没有判断ID是否为数字等,这等以后去慢慢完善了:)