JS 在线投票功能(不用到数据库)

JavaScript02

JS 在线投票功能(不用到数据库),第1张

东拼西凑的,而且只在ie下有效,不过网上有兼容ff的代码,以下是html代码

<!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>

给你提供思路

1.点击投票button调用 方法 方法里面设置一个定时器setInterval 定时器里面循环切换2个球的颜色

点击停的时候停止定时器

var flag = 0//全局flag

var id//定时器

$("#btnStart").click=function(){

if(this.value=="开始"){

this.value="停止"

id = window.setInterval(function(){

if(flag==0){

flag = 1

$("#btn1").css("bgcolor","red")

$("#btn1").css("bgcolor","blur")}else{

flag = 0

$("#btn1").css("bgcolor","blur")

$("#btn1").css("bgcolor","red")

}

},100)//0.1毫秒 随便你自己设

}else{

this.value="开始"

//取消定时

window.clearInterval(id)

}

}

具体自己修修

望采纳!

<script language="javascript">

function check(form)

{

var pamas = document.getElementsByName("投票项的NAME值")

var count = 0

for (i=0i<pamas.lengthi++){

if(pamas[i].checked == true){

count++

}

}

if(count!=5)

{

alert("必须同时选择5个人才能进行投票!")

form.name.focus()

return false

}

</script>