js实现弹窗提示,N秒后自动关闭并跳转页面
2015-05-20 17:29
1056 查看
前端部分
<style>
.overlay{
background:transparent url(images/overlay.png) repeat top left;
position:fixed;
top:0px;
bottom:0px;
left:0px;
right:0px;
z-index:100;
}
.box{
position:fixed;
background:rgba(0,0,0,0.8);
color:#fff; height:30px;
margin-top:-15px;
top:-100%;
left:50%;
width:100%; text-align:center; line-height:30px;
margin-left:-130px;
-moz-border-radius: 5px;
-webkit-border-radius:5px;
-khtml-border-radius:5px;
z-index:101;
}
</style>
<div class="overlay" id="overlay" style="display:none;"></div>
<div class="box" id="box" style="width:250px;z-index:99999999">恭喜您提交成功,您已获得{$question.joined_points}积分</div>
<script>
function tishi(){
$('#overlay').fadeIn('fast', function () {
$('#box').animate({ 'top': '50%' }, 500);
$("#mess").html();
setTimeout("tishiclose()",2000);//2秒消失,可以改动
});
}
function tishiclose(){
$('#box').animate({ 'top': '-100%' }, 500, function () {
$('#overlay').fadeOut('fast');
});
}
//跳转地址
function skip(){
location.href="{:U('Survey/detail')}";
}
$('#sub').click(function(){
var xuan=document.getElementsByName("xuanx");//不能getElementById,ById又只会读数组第一个值
var xuanxid;
for(var i = 0; i < xuan.length; i++)
{
if(xuan[i].checked)
xuanid=xuan[i].value;
}
var url="__URL__/get_answer";
var postdata = "xuanx="+xuanid;
$.post(url,postdata,function(data){
if(data.c == 1){
$('#overlay').fadeIn('fast', function () {
$('#box').animate({ 'top': '50%' }, 500);
//$("#mess").html();
setTimeout("tishiclose()",2000);//2秒消失,可以改动
});
setInterval("skip()", 2000);
}else{
alert(data.m);
return false;
}
})
})
</script>
后端php部分
//ajax提交用户选择问题的答案
public function get_answer(){
$userid = I('session.uid');
$xuanx = I('request.xuanx',"");
$question_id =1;
$user_question = M('WenjuanAnsinfo')->where(array('user_id'=>$userid,'question_id'=>$question_id))->select();
if(!$user_question){
$data = array(
'question_id'=>1,
'user_id'=>$userid,
'ans_id'=>$xuanx,
'ans_date'=>time(),
);
$add = M('WenjuanAnsinfo')->add($data);
$wenjuan_point = M('WenjuanQuestion')->where(array('question_id'=>$question_id))->find();
//赠送积分
$getPoints = M('UserPoint')->where(array('user_id'=>$userid))->setInc('points',$wenjuan_point['joined_points']);
$joined_count = M('WenjuanAnsinfo')->where(array('question_id'=>1))->count();
M('WenjuanQuestion')->where(array('question_id'=>1))->save(array('joined_count'=>$joined_count));
if($add && $getPoints){
set_return_value('成功', 1, null);
}else{
set_return_value('提交问卷调查失败', 0, null);
}
}
}
<style>
.overlay{
background:transparent url(images/overlay.png) repeat top left;
position:fixed;
top:0px;
bottom:0px;
left:0px;
right:0px;
z-index:100;
}
.box{
position:fixed;
background:rgba(0,0,0,0.8);
color:#fff; height:30px;
margin-top:-15px;
top:-100%;
left:50%;
width:100%; text-align:center; line-height:30px;
margin-left:-130px;
-moz-border-radius: 5px;
-webkit-border-radius:5px;
-khtml-border-radius:5px;
z-index:101;
}
</style>
<div class="overlay" id="overlay" style="display:none;"></div>
<div class="box" id="box" style="width:250px;z-index:99999999">恭喜您提交成功,您已获得{$question.joined_points}积分</div>
<script>
function tishi(){
$('#overlay').fadeIn('fast', function () {
$('#box').animate({ 'top': '50%' }, 500);
$("#mess").html();
setTimeout("tishiclose()",2000);//2秒消失,可以改动
});
}
function tishiclose(){
$('#box').animate({ 'top': '-100%' }, 500, function () {
$('#overlay').fadeOut('fast');
});
}
//跳转地址
function skip(){
location.href="{:U('Survey/detail')}";
}
$('#sub').click(function(){
var xuan=document.getElementsByName("xuanx");//不能getElementById,ById又只会读数组第一个值
var xuanxid;
for(var i = 0; i < xuan.length; i++)
{
if(xuan[i].checked)
xuanid=xuan[i].value;
}
var url="__URL__/get_answer";
var postdata = "xuanx="+xuanid;
$.post(url,postdata,function(data){
if(data.c == 1){
$('#overlay').fadeIn('fast', function () {
$('#box').animate({ 'top': '50%' }, 500);
//$("#mess").html();
setTimeout("tishiclose()",2000);//2秒消失,可以改动
});
setInterval("skip()", 2000);
}else{
alert(data.m);
return false;
}
})
})
</script>
后端php部分
//ajax提交用户选择问题的答案
public function get_answer(){
$userid = I('session.uid');
$xuanx = I('request.xuanx',"");
$question_id =1;
$user_question = M('WenjuanAnsinfo')->where(array('user_id'=>$userid,'question_id'=>$question_id))->select();
if(!$user_question){
$data = array(
'question_id'=>1,
'user_id'=>$userid,
'ans_id'=>$xuanx,
'ans_date'=>time(),
);
$add = M('WenjuanAnsinfo')->add($data);
$wenjuan_point = M('WenjuanQuestion')->where(array('question_id'=>$question_id))->find();
//赠送积分
$getPoints = M('UserPoint')->where(array('user_id'=>$userid))->setInc('points',$wenjuan_point['joined_points']);
$joined_count = M('WenjuanAnsinfo')->where(array('question_id'=>1))->count();
M('WenjuanQuestion')->where(array('question_id'=>1))->save(array('joined_count'=>$joined_count));
if($add && $getPoints){
set_return_value('成功', 1, null);
}else{
set_return_value('提交问卷调查失败', 0, null);
}
}
}
相关文章推荐
- JS实现页面超时后自动跳转到登陆页面
- 实现页面自动刷新,页面自动跳转,页面自动关闭
- JS实现页面(窗口)直接关闭 ,无需提示
- JS实现页面超时后自动跳转到登陆页面
- ASP.NET中配合JS实现页面计时(定时)自动跳转
- js 页面关闭前的出现提示的实现代码
- JS自动关闭授权弹窗,并刷新父页面
- JS实现页面超时后自动跳转到登陆页面
- ASP.NET中配合JS实现页面计时(定时)自动跳转
- JS实现页面超时后自动跳转到登陆页面
- javascript/js 自动刷新页面和页面跳转的实现方法
- laery.js提示层结束之后自动跳转到新页面
- 实现session超时后自动跳转到登陆页面(前台JS,JAVA,判断是否Ajax请求)
- js实现浏览器右下角弹出提示信息窗口,几秒后自动关闭
- 页面自动跳转的js实现
- 等待指定时间后自动跳转或关闭当前页面的js代码
- 使用js实现页面自动跳转
- js实现页面自动跳转
- Asp.net实现网站提示信息页面后的定时自动跳转到指定页面
- js实现页面自动跳转(不加重前页面,直接加载跳转页)