我在下面做了一個(gè)off與on的判斷,但當(dāng)我想提交按鈕時(shí)會(huì)彈出('評(píng)價(jià)失敗請(qǐng)重試');因?yàn)樵谙旅鏁r(shí)的num值在ajax時(shí)沒有,所以才有這個(gè)問題,如何讓下面的num,獲取到?// num為點(diǎn)亮星星的數(shù)量,$(function () {var num = 0;//實(shí)現(xiàn)星星效果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('您不滿足評(píng)價(jià)條件');} else {alert('評(píng)價(jià)失敗請(qǐng)重試');}}})})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("時(shí)間:" + 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');}})}
js傳遞問題
彬彬有理_0
2017-06-27 19:32:59