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为文件名;后两句是将字符串写入文件和关闭输出流文件。
<!doctype html><html lang="en">
<head>
<meta charset="UTF-8">
<style>
.div_bor{
border:1px solid #274b8b
padding: 5px 5px 10px 5px
}
</style>
</head>
<body>
<div class="div_bor">
<p>这是题目</p>
<p><input type="checkbox" value="A">A.选项1</p>
<p><input type="checkbox" value="B">B.选项2</p>
<p><input type="checkbox" value="C">C.选项3</p>
<p><input type="checkbox" value="D">D.选项4</p>
<p><input type="checkbox" value="E">E.选项5</p>
<p><button style="float: right" onclick="fn()">确定</button></p>
</div>
<script>
var rule = ['A','C','D']//答案
var boxs = document.getElementsByTagName('input')
var check = []
var score = 0
function fn(){
check=[]
score = 0
for(var i=0i<boxs.lengthi++){
if(boxs[i].checked){
check.push(boxs[i].value)
}
}
for(var j=0j<check.lengthj++){
if(rule.indexOf(check[j]) !=-1){
score++
}else{
score--
}
}
alert(Math.ceil(100/rule.length*score)+'分')// 分数规则,自己定吧
}
</script>
</body>
</html>
<html><body>
<p>Tell Me About Yourself</p>
<br>
<form action="/action_page.php">
What is Your Name? <input type="text" name="name">
<br>
How old are you? <input type="text" name="old">
<br>
<p>What are your favorite subjects?</p>
<select name="subjects" size="3" multiple="multiple">
<option value="Math">Math</option>
<option value="Science">Science</option>
<option value="English">English</option>
<option value="History">History</option>
<option value="Art">Art</option>
<option value="Music">Music</option>
<option value="Social Studies">Social Studies</option>
<option value="Physics">Physics</option>
<option value="Chemistry">Chemistry</option>
<option value="Biology">Biology</option>
</select>
<form action=""method="get">
<p>Are you a boy ot a girl?</p>
<br>
<input type="radio"name="gender"value="girl"/>a girl
<input type="radio"name="gender"value="boy"/>a boy
<p>About My Web Site</p>
<form action=""method="get">
<p>What were your favorite pages?</p>
<input type="checkbox"name="page"value="home"/>Home
<input type="checkbox"name="page"value="about"/>About
<input type="checkbox"name="page"value="school"/>School
<input type="checkbox"name="page"value="hobbies"/>Hobbies
</p>
</form>
<form action=""mathod="get">
<p>please leave comment</p>
<textarea name="comments"/></textarea>
<p>
</form>
<input type="submit">
<input type="reset">
</body>
</html>
一个简单的调查问卷,望采纳
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)