<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/htmlcharset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<input type="button" value="投票" onclick="javascript:addvote()" /><br />
文本:<span id="t"></span>
<script>
loadXML = function(xmlFile){
var xmlDoc
if(window.ActiveXObject){
xmlDoc = new ActiveXObject('Microsoft.XMLDOM')
xmlDoc.async = false
xmlDoc.load(xmlFile)
}
else if (document.implementation&&document.implementation.createDocument){
xmlDoc = document.implementation.createDocument('','',null)
xmlDoc.load(xmlFile)
}
else{
return null
}
return xmlDoc
}
checkXMLDocObj = function(xmlFile){
var xmlDoc = loadXML(xmlFile)
if(xmlDoc==null){
alert('您的浏览器不支持xml文件读取,于是本页面禁止您的操作,推荐使用IE5.0以上可以解决此问题!')
window.location.href='/Index.aspx'
}
return xmlDoc
}
function addvote(){
var xmlDoc = checkXMLDocObj("vote.xml")
var text = xmlDoc.getElementsByTagName("time")[0].childNodes[0]
text.nodeValue++
document.getElementById("t").innerHTML=text.nodeValue
var fso, tf
fso = new ActiveXObject("scripting.FileSystemObject")
// 创建新文件
tf = fso.CreateTextFile("vote.xml", true)
// 填写数据,并增加换行符
tf.WriteLine("<?xml version=\"1.0\" encoding=\"gb2312\"?>")
tf.WriteLine("<vote>")
tf.WriteLine("<time>"+text.nodeValue+"</time>")
tf.WriteLine("</vote>")
// 关闭文件
tf.Close()
}
</script>
</body>
</html>
以下是vote.xml
<?xml version="1.0" encoding="gb2312"?>
<vote>
<time>0</time>
</vote>