• 手机版

    扫码体验手机版

  • 微信公众号

    扫码关注公众号

国内首家协议开发

软芯音视解码保护平台

在线
客服

发布
需求

在线
聊天

天盟
APP

天盟APP下载

关注
微信

微信扫一扫访问
顶部

js传递问题

我在下面做了一个off与on的判断,但当我想提交按钮时会弹出('评价失败请重试');因为在下面时的num值在ajax时没有,所以才有这个问题,如何让下面的num,获取到?
// num为点亮星星的数量,
$(function () {
var num = 0;
//实现星星效果

var $rating = $('#rating')
lightOn(num);
$rating.on('mouseover', '.rating-item', function () {
lightOn($(this).index() + 1);
}).on('click', '.rating-item', function () {
num = $(this).index() + 1;
}).on('mouseout', function () {
lightOn(num);
return num;
});
//提交文字表单
$('#info-button').on('click', function () {
$.ajax({
type: 'post',
url: "{:U('User/Index/evaluate')}",
data: {
score: num,
textarea: $("textarea[name='from-textarea']").val(),
id: $("input[name='id']").val()
},
dataType: 'json',
success: function (data) {
if (data != 0) {
hideShow('.form-text', '.success');
$('.close-success').on('click', function () {
$('.success').hide();
num = 0;
$("textarea[name='from-textarea']").val('');
act(data);
});
} else if (data == -1) {
alert('您不满足评价条件');
} else {
alert('评价失败请重试');
}


}
})


})
function act(uid, object) {

// var object = arguments[1]?arguments:0;
// if(object != 0){
//     $('#list-ul>li').removeClass('active');
//     $(object).addClass('active');
// }   
// $(object).addClass('active');
$.ajax({
type: 'post',
url: "{:U('User/Index/getevaluate')}",
data: {
id: uid
},
dataType: 'json',
success: function (obj) {
hideShow('.unchanged', '.info');
$('.username').html(obj['data']['name']);
$('.job_number').html(obj['data']['job_number']);
$('.u-pic img').attr('src', obj['data']['thumb']);
$('.motto').html(obj['data']['motto']);
if (obj['res'] == 0) {
$('.info').removeClass('show-con');
lightOn(0);
$("input[name='id']").val(obj['data']['id']);
hideShow('.text-show', '.form-text');
var num=0;
$('#rating').on('mouseover', '.rating-item', function () {
lightOn($(this).index() + 1);
})
$('#rating').on('click', '.rating-item', function () {
num = $(this).index() + 1;
})
$('#rating').on('mouseout', function () {
lightOn(num);
console.log(num)
return num;
});
} else {
$(".info").addClass('show-con');
hideShow('.form-text', '.text-show');
$('.name').html("用户:" + obj['data']['user_name']);
$('.ctime').html("时间:" + obj['data']['create_time']);
$('.cont').html(obj['data']['cont']);
lightOn(obj['data']['score']);
if(obj['data']['score'] >= 1){
$('#rating').off("mouseover");
$('#rating').off("mouseout");
$('#rating').off("click");
}
}
}
})


}


function lightOn(n) {
var $rating = $('#rating'),
$item = $rating.find('.rating-item');
$item.each(function (index) {
if (index < n) {
$(this).addClass('action');
} else {
$(this).removeClass('action');
}
})
}

免责声明:本内容仅代表回答会员见解不代表天盟观点,请谨慎对待。

版权声明:作者保留权利,不代表天盟立场。

使用道具 举报

全部参与1

按你的思路,把num声明为全局变量即可。

使用道具 举报

发新帖

发布任务需求已有1031168位用户正在使用天盟网服务

发布分类: *
任务预算: *
需求内容: *
手机号码: *
任务商家报价为
  • 预算价 :
  • 成交价 :
  • 完工期 :
  • 质保期 :

* 最终任务项目以服务商报价、双方协商为准!