亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

js傳遞問題

js傳遞問題

彬彬有理_0 2017-06-27 19:32:59
我在下面做了一個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 回答

?
范克里夫

TA貢獻1條經驗 獲得超0個贊

按你的思路,把num聲明為全局變量即可。

查看完整回答
反對 回復 2017-11-15
  • 1 回答
  • 0 關注
  • 1666 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號