乔贤论坛

 找回密码
 立即注册(中文)
fake tag heuer watches replica swiss watches buy watches online best replica watch cheap fake watches swiss replica rolex replicas rolex swiss rolex replica rolex swiss replica rolex watches replica fake rolex watch fake breitling breitling fake breitling watches replica fake swiss watches replica fake watches quality imitation watches replica breitling watch fake cartier watches replica breitling watches
搜索
查看: 793|回复: 0
打印 上一主题 下一主题

Asp实现Dig程序中的投票代码

[复制链接]
跳转到指定楼层
楼主
黄天火 发表于 2011-2-22 23:40:21 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
网页显示投票的部分:

<div class="Vote1"><script src='/voteResult.asp?id=1&action=view'></script></div>

效果如图:


,然后点投一票,票数增加1,如图:


voteResult.asp代码
<%
Response.ContentType="text/html; charset=gb2312"

'作者:无情 来源:http://www.dwww.cn 转载请保留出处
'链接数据库代码省略
set rs=server.createobject("adodb.recordset")
sql=("select news_id,vote from dwww_news where news_id="&request("id")&"")
rs.open sql,conn,1,1

if not rs.eof and not rs.bof Then '先检查传过来的id是否正确

if request("action")="view" Then '如果是新闻代码中传来的id
if instr(request.Cookies("voteid"),request("id")&"|")<>0 Then '判断该id的新闻是否投过票
response.write "document.write (""<div class='result' id='result_"&rs("news_id")&"'>"&rs("vote")&"</div>"");"
response.write "document.write (""<span class='result_link' id='result_link_"&rs("news_id")&"'>投票成功</span>"");"
else
response.write "document.write (""<div class='result' id='result_"&rs("news_id")&"'><a href='javascript:dovote("&request("id")&")'>"&rs("vote")&"</a></div>"");"
response.write "document.write (""<span class='result_link' id='result_link_"&rs("news_id")&"'><a href='javascript:dovote("&request("id")&")'>投一票</a></span>"");"
end if
Else '点击投票处理代码
if instr(request.Cookies("voteid"),request("id")&"|")<>0 then
Response.Cookies("voteid")=request("id")&"|"
Response.Cookies("voteid").Expires=Date()+365
else
Response.Cookies("voteid")=request("id")&"|"&request.Cookies("voteid")
Response.Cookies("voteid").Expires=Date()+365
end If

vote=rs("vote")+1
conn.execute ("update dwww_news set vote=vote+1 where news_id="&request("id")&"")

response.write ""&vote&""
end If

end if

rs.close()
Set rs=Nothing

'关闭数据库代码省略
%>

其中程序中用到的css代码:

voteBg.gif 图片

.Vote1{float:left;width:54px;height:71px;background:url(/images/voteBg.gif);margin:0 5 0 0;text-align:center; }
.DivAllShow2 .Vote1{float:left;width:54px;height:71px;background:url(/images/voteBg.gif);margin:6 5 0 0;text-align:center; }
.vote1 div{height:44px;line-height:44px;font-size:18px; font-weight:bold;font-family:Georgia;color:#333333;}
.result a:link{font-size:18px; font-weight:bold;text-decoration:none;}
.result a:visited {font-size:18px; font-weight:bold;text-decoration:none;}
.result a:hover {font-size:18px; font-weight:bold;text-decoration:none;}
.Vote1 span{height:20px;line-height:20px;color:#CE4A02;margin:5 0 0 0;}
.result_link a:link{color:#CE4A02;text-decoration:none;}
.result_link a:visited {color:#CE4A02;text-decoration:none;}
.result_link a:hover {color:#CE4A02;text-decoration:none;}
js代码:
var http_request = false;
function send_request(url,votei) {//初始化、指定处理函数、发送请求的函数
http_request = false;
//开始初始化XMLHttpRequest对象
if(window.XMLHttpRequest) { //Mozilla 浏览器
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {//设置MiME类别
http_request.overrideMimeType('text/xml');
}
}
else if (window.ActiveXObject) { // IE浏览器
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
if (!http_request) { // 异常,创建对象实例失败
window.alert("不能创建XMLHttpRequest对象实例.");
return false;
}

http_request.onreadystatechange = function(){processRequest(votei)};

// 确定发送请求的方式和URL以及是否同步执行下段代码
http_request.open("post", url, true);
http_request.send(null);

}
// 处理返回信息的函数
function processRequest(votei) {
if (http_request.readyState == 4) { // 判断对象状态
if (http_request.status == 200) { // 信息已经成功返回,开始处理信息
//alert(http_request.responseText);

document.getElementById('result_'+votei).innerHTML=http_request.responseText;;
document.getElementById('result_link_'+votei).innerHTML = "投票成功";

} else { //页面不正常
alert("您所请求的页面有异常。");
}
}
}
function dovote(votei)
{
var votei=votei;
send_request('/voteResult.asp?id='+escape(votei),votei);
}

function getObj(objName){return(document.getElementById(objName));}
您需要登录后才可以回帖 登录 | 立即注册(中文)

本版积分规则

关闭

站长推荐上一条 /1 下一条

QQ|小黑屋|手机版|Archiver|乔贤论坛  

GMT+8, 2024-11-14 13:48 , Processed in 0.081463 second(s), 19 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表