pencat=rs.Fields.Item("m_content").Value
pencat=replace(pencat,"t_title",n_title)
pencat=replace(pencat,"t_author",n_author)
pencat=replace(pencat,"t_content",n_content)
Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set fout = fso.CreateTextFile(server.mappath(fpath&"\" &fname))
fout.WriteLine pencat
fout.close
2、如下给出要生成的网页模板:
<html>
<head>
<meta http-equiv=""Content-Language"" content=""zh-cn"">
<meta http-equiv=""Content-Type"" content=""text/htmlcharset=gb2312"">
<meta name=""GENERATOR"" content=""Microsoft FrontPage 4.0"">
<meta name=""ProgId"" content=""FrontPage.Editor.Document"">
<title></title>
</head>
<body topmargin=""0"" leftmargin=""0"">
<table border=""0"" width=""760"" height=""100%"" background=""background.jpg"" >
<tr>
<td width=""752"" height=""10"" colspan=""3"">
<p align=""center"">t_title
</td>
</tr>
<tr>
<td width=""752"" height=""18"" colspan=""3"">
<div align=""center"">
</div>
<div align=""center"">
<font size=""2"">
作者:</font><font color=""#990000"">t_author</font>
<font size=""2"">
加入时间:</font><font color=""#990000"">t_date</font>
</div>
</td>
</tr>
<tr>
<td width=""15%"" height=""100%"" valign=""top"">
</td>
<td width=""70%"" height=""100%"" valign=""top"">
t_content
</td>
<td width=""15%"" height=""100%"" valign=""top"">
</td>
</tr>
</table>
</body>
</html>
3、解释
(1)pencat=rs.Fields.Item("m_content").Value
pencat为一个字符串变量。
rs.Fields.Item("m_content").Value就是如上2、网页模板的全部HTML字符
(2)pencat=replace(pencat,"t_title",n_title)
pencat=replace(pencat,"t_author",n_author)
pencat=replace(pencat,"t_content",n_content)
以上三句就是将字符串中的字串替换成为你所需要的内容,即ASP中动态获得的内容。
(3)Set fso = Server.CreateObject("Scripting.FileSystemObject")
Set fout = fso.CreateTextFile(server.mappath(fpath&"\" &fname))
fout.WriteLine pencat
fout.close
以上为将刚刚组合所得的网页代码写入文件的过程。第一句定义fso文件,第二句创建输出流文件,其中fpath为你想要存储的文件的路径,fname为文件名;后两句是将字符串写入文件和关闭输出流文件。
HTML做个数据录入的模板。如下参考:
1、首先新建一个html,点击<body></body>中间,先填入表格内容:
2.内容可根据要求编写,示例代码如下:
<table>
<p style="text-align:center ">功课表</p>
<tr>
<th>语文</th>
<td>7:00-7:40</td>
<td>7:50-8:30</td>
</tr>
<tr>
<th>数学</th>
<td>7:00-7:40</td>
<td>7:50-8:30</td>
</tr>
<tr>
<th>英文</th>
<td>7:00-7:40</td>
<td>7:50-8:30</td>
</tr>
</table>
3.然后在<head></head>中间输入样式表的样式,如下图:
4.样式也可以根据个人需要设置,设置单元格的宽度高度,合并单元格,位置,颜色等,示例代码如下:
<style type="text/css">
body
{
width:340px
height:800px
}
table
{
border-collapse:collapse
}
th,td
{
width:100px
height:40px
border:1pxsolidblack
font-size:12px
text-align:center
}
</style>
5.注意,此代码“table的意思是表”的含义是将表边框合并为单个边框以合并相邻的更改。
6.预览结果如下图所示,一个制作简单的HTML模板。
<!doctype html><html>
<head>
<meta charset="UTF-8">
<title>多项选择题</title>
<style type="text/css">
label{background:#ccffff}
</style>
</head>
<body>
<h1>测试题</h1><hr>
<h2>一、单项选择题</h2>
<div id="dan1">
<p>1.世界上谁最帅?</p>
<p><input type="radio" id="dA1" name="dan1"><label for="dA1">A.李小龙</p>
<p><input type="radio" id="dB1" name="dan1"><label for="dB1">B.李连杰</p>
<p><input type="radio" id="dC1" name="dan1"><label for="dC1">C.陈小春</p>
<p><input type="radio" id="dD1" name="dan1"><label for="dD1">D.刘德华</p>
<input type="button" value="提交答案" onclick="dan1_answer()"><hr>
<span id="d1_tetion"></span>
</div>
<div id="dan2">
<p>2.世界上谁最帅?</p>
<p><input type="radio" id="dA2" name="dan2"><label for="dA2">A.李小龙</p>
<p><input type="radio" id="dB2" name="dan2"><label for="dB2">B.李连杰</p>
<p><input type="radio" id="dC2" name="dan2"><label for="dC2">C.陈小春</p>
<p><input type="radio" id="dD2" name="dan2"><label for="dD2">D.刘德华</p>
<input type="button" value="提交答案" onclick="dan2_answer()"><hr>
<span id="d2_tetion"></span>
</div>
<div id="dan3">
<p>3.世界上谁最帅?</p>
<p><input type="radio" id="dA3" name="dan3"><label for="dA3">A.李小龙</p>
<p><input type="radio" id="dB3" name="dan3"><label for="dB3">B.李连杰</p>
<p><input type="radio" id="dC3" name="dan3"><label for="dC3">C.陈小春</p>
<p><input type="radio" id="dD3" name="dan3"><label for="dD3">D.刘德华</p>
<input type="button" value="提交答案" onclick="dan3_answer()"><hr>
<span id="d3_tetion"></span>
</div>
<div id="dan4">
<p>4.世界上谁最帅?</p>
<p><input type="radio" id="dA4" name="dan4"><label for="dA4">A.李小龙</p>
<p><input type="radio" id="dB4" name="dan4"><label for="dB4">B.李连杰</p>
<p><input type="radio" id="dC4" name="dan4"><label for="dC4">C.陈小春</p>
<p><input type="radio" id="dD4" name="dan4"><label for="dD4">D.刘德华</p>
<input type="button" value="提交答案" onclick="dan4_answer()"><hr>
<span id="d4_tetion"></span>
</div>
<div id="dan5">
<p>5.世界上谁最帅?</p>
<p><input type="radio" id="dA5" name="dan5"><label for="dA5">A.李小龙</p>
<p><input type="radio" id="dB5" name="dan5"><label for="dB5">B.李连杰</p>
<p><input type="radio" id="dC5" name="dan5"><label for="dC5">C.陈小春</p>
<p><input type="radio" id="dD5" name="dan5"><label for="dD5">D.刘德华</p>
<input type="button" value="提交答案" onclick="dan5_answer()"><hr>
<span id="d5_tetion"></span>
</div>
<h2>二、多项选择题</h2>
<div id="box">
<p>1.一栋房子由哪几部分组成?</p>
<p><input type="checkbox" id="A"><label for="A">A.地基与基础,主体结构,屋面工程</label></p>
<p><input type="checkbox" id="B"><label for="B">B.装饰装修、给排水及采暖工程</label></p>
<p><input type="checkbox" id="C"><label for="C">C.空调与通风工程</label></p>
<p><input type="checkbox" id="D"><label for="D">D.智能化建筑工程</label></p>
<p><input type="checkbox" id="E"><label for="E">E.电梯工程、电气工程、节能工程</label></p>
<input type="button" value="提交答案" onclick="answer()"><hr>
<span id="tetion"></span>
</div>
<div id="box2">
<p>2.一栋房子由哪几部分组成?</p>
<p><input type="checkbox" id="A2"><label for="A2">A.地基与基础,主体结构,屋面工程</label></p>
<p><input type="checkbox" id="B2"><label for="B2">B.装饰装修、给排水及采暖工程</label></p>
<p><input type="checkbox" id="C2"><label for="C2">C.空调与通风工程</label></p>
<p><input type="checkbox" id="D2"><label for="D2">D.智能化建筑工程</label></p>
<p><input type="checkbox" id="E2"><label for="E2">E.电梯工程、电气工程、节能工程</label></p>
<input type="button" value="提交答案" onclick="answer2()"><hr>
<span id="tetion2"></span>
</div>
<div id="box3">
<p>3.一栋房子由哪几部分组成?</p>
<p><input type="checkbox" id="A3"><label for="A3">A.地基与基础,主体结构,屋面工程</label></p>
<p><input type="checkbox" id="B3"><label for="B3">B.装饰装修、给排水及采暖工程</label></p>
<p><input type="checkbox" id="C3"><label for="C3">C.空调与通风工程</label></p>
<p><input type="checkbox" id="D3"><label for="D3">D.智能化建筑工程</label></p>
<p><input type="checkbox" id="E3"><label for="E3">E.电梯工程、电气工程、节能工程</label></p>
<input type="button" value="提交答案" onclick="answer3()"><hr>
<span id="tetion3"></span>
</div>
<div id="box4">
<p>4.一栋房子由哪几部分组成?</p>
<p><input type="checkbox" id="A4"><label for="A4">A.地基与基础,主体结构,屋面工程</label></p>
<p><input type="checkbox" id="B4"><label for="B4">B.装饰装修、给排水及采暖工程</label></p>
<p><input type="checkbox" id="C4"><label for="C4">C.空调与通风工程</label></p>
<p><input type="checkbox" id="D4"><label for="D4">D.智能化建筑工程</label></p>
<p><input type="checkbox" id="E4"><label for="E4">E.电梯工程、电气工程、节能工程</label></p>
<input type="button" value="提交答案" onclick="answer4()"><hr>
<span id="tetion4"></span>
</div>
<div id="box5">
<p>5.一栋房子由哪几部分组成?</p>
<p><input type="checkbox" id="A5"><label for="A5">A.地基与基础,主体结构,屋面工程</label></p>
<p><input type="checkbox" id="B5"><label for="B5">B.装饰装修、给排水及采暖工程</label></p>
<p><input type="checkbox" id="C5"><label for="C5">C.空调与通风工程</label></p>
<p><input type="checkbox" id="D5"><label for="D5">D.智能化建筑工程</label></p>
<p><input type="checkbox" id="E5"><label for="E5">E.电梯工程、电气工程、节能工程</label></p>
<input type="button" value="提交答案" onclick="answer5()"><hr>
<span id="tetion5"></span>
</div>
<script type="text/javascript">
function dan1_answer(){dan_answer("dA1","dB1","dC1","dD1","dan1","d1_tetion","A")}
function dan2_answer(){dan_answer("dA2","dB2","dC2","dD2","dan2","d2_tetion","B")}
function dan3_answer(){dan_answer("dA3","dB3","dC3","dD3","dan3","d3_tetion","B")}
function dan4_answer(){dan_answer("dA4","dB4","dC4","dD4","dan4","d4_tetion","C")}
function dan5_answer(){dan_answer("dA5","dB5","dC5","dD5","dan5","d5_tetion","C")}
function dan_answer(da,db,dc,dd,dan,d_tetion,pd){
var A=document.getElementById(da).checked//alert(A)
var B=document.getElementById(db).checked
var C=document.getElementById(dc).checked
var D=document.getElementById(dd).checked
var d_Rightanswer=pd
var passW=saot(d_Rightanswer)//alert(passW)
var youW=saot([A,B,C,D])//alert(youW)
var youD=transABCDE([A,B,C,D])//你的答案
if(passW==youW){
document.getElementById(dan).innerHTML+="<style>#"+d_tetion+"{color:yellowbackground:red}</style>"
document.getElementById(d_tetion).innerHTML="你的答案:"+youD+"<br>---恭喜您,答对了!"}else{
document.getElementById(dan).innerHTML+="<style>#"+d_tetion+"{color:redbackground:#ccc}</style>"
document.getElementById(d_tetion).innerHTML="你的答案:"+youD+"<br>---回答错误!正确答案是:"+d_Rightanswer
}
}
function answer(){answerALL("A","B","C","D","E","box","tetion","ABCDE")}
function answer2(){answerALL("A2","B2","C2","D2","E2","box2","tetion2","ABCDE")}
function answer3(){answerALL("A3","B3","C3","D3","E3","box3","tetion3","ABCDE")}
function answer4(){answerALL("A4","B4","C4","D4","E4","box4","tetion4","ABCDE")}
function answer5(){answerALL("A5","B5","C5","D5","E5","box5","tetion5","ABCDE")}
function answerALL(a,b,c,d,e,box,tetion,RT){
var A=document.getElementById(a).checked
var B=document.getElementById(b).checked
var C=document.getElementById(c).checked
var D=document.getElementById(d).checked
var E=document.getElementById(e).checked
var arr=[A,B,C,D,E]
var youD=transABCDE(arr)//你的答案
var numA=saot(arr)
var Rightanswer=RT//将正确答案填在这里
var numB=saot(Rightanswer)
if(numA==numB){
document.getElementById(box).innerHTML+="<style>#"+tetion+"{color:yellowbackground:red}</style>"
document.getElementById(tetion).innerHTML="你的答案:"+youD+"<br>---恭喜您,答对了!"
}else{
document.getElementById(box).innerHTML+="<style>#"+tetion+"{color:redbackground:#ccc}</style>"
document.getElementById(tetion).innerHTML="你的答案:"+youD+"<br>---回答错误!正确答案是:"+Rightanswer
}
}
function transAtoN(answer){//将正确答案字母组成的字符串转换成一串0和1的数字
var arr=answer
var c=arr.split("")//分割字符串变成数组
//alert(c)
var num=0
for(var i in c){
if(c[i]=="A" || c[i]=="a"){num+=10000}
if(c[i]=="B" || c[i]=="b"){num+=1000}
if(c[i]=="C" || c[i]=="c"){num+=100}
if(c[i]=="D" || c[i]=="d"){num+=10}
if(c[i]=="E" || c[i]=="e"){num+=1}
}
return num
}
function transBER(arr){//将在多项选择中获得的选择布尔值转换成一串0和1的数字
var num=0
if(arr[0]){num+=10000}
if(arr[1]){num+=1000}
if(arr[2]){num+=100}
if(arr[3]){num+=10}
if(arr[4]){num+=1}
return num
}
function saot(t){//合并布尔值和字符串转成数字,自动选择适应程序!
if(typeof t=="string"){
var geta=transAtoN(t)
return geta
}else{
var getb=transBER(t)
return getb
}
}
function transABCDE(arr){
var chara=""
if(arr[0]){chara+="A"}
if(arr[1]){chara+="B"}
if(arr[2]){chara+="C"}
if(arr[3]){chara+="D"}
if(arr[4]){chara+="E"}
return chara
}
//alert(transABCDE([true,false,true]))
</script>
</body>
</html>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)