我在下面做了一个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');}})}
添加回答
举报
0/150
提交
取消