一段jquery代码求解
function setcalc(obj,type){
var $calc_list = $('#calc_list');
if(!onproc){
onproc = true;
$.ajax({
url:$calc_list.attr('data-url'),
type:'post',
data:{log_id:$calc_list.attr('rel'),tran_type:type},
success:function(json){
eval('var ary='+json+';');
if(ary.code==4){
alert(ary.msg);
onproc = false;
}else if(ary.code==50){
//alert(ary.msg);
window.location.href = 'index.php?pluginid=money&con=wap&act=count';
}else {
var ary_tran_type = new Array();
ary_tran_type[0] = '+0';
ary_tran_type[1] = '+666';
ary_tran_type[2] = '+888';
ary_tran_type[3] = '-555';
ary_tran_type[4] = '-333';
$(obj).find('p').removeClass('buttom-my2').addClass('buttom-my1');
$('#w_rank').text(ary.w_rank);
$('#t_rank').text(ary.t_rank);
$('#log_credit').text(ary.credit);
$('#tran_name').text(ary.tran_name);
$('#f_text').text(ary.tran_type>2? '人品堪忧' : '人品极好');
$('#tran_result').text(ary_tran_type[ary.tran_type]);
$('#calc_1').addClass('disn');
$('#calc_2').removeClass('disn');
}
}
});
}
}
大神帮忙分析一下这段代码
我传值
<a class="tc cr-fff f30 fb lh126 fl ml25 mr10 buttom-my1" onclick="setcalc(this,2)">
<p class="buttom-my0 bor-r-8bb3c2 mr10"><img class="" src="plugins/money/views/images/dian.png"></p>
</a>
传值2进去会得到什么结果
</script> <script>
$(function(){
$('#btn_share').bind('click',function(){
$('#tip_shadow').removeClass('disn');$('#share_tip').removeClass('disn');
});
});
</script>
<script>var cnzz_protocol = (("https:" == document.location.protocol) ? " https://" : " http://");document.write(unescape("%3Cspan id='cnzz_stat_icon_1253518145'%3E%3C/span%3E%3Cscript src='" + cnzz_protocol + "v1.cnzz.com/z_stat.php%3Fid%3D1253518145' type='text/javascript'%3E%3C/script%3E"));</script> 展开
var onproc = false; //初始化false
$("#XX"):是获取id为XX的元素
function setcalc(obj,type){
var $calc_list = $('#calc_list'); //获取元素$('#calc_list')
if(!onproc){ //进行判断
onproc = true;
//执行异步方法
$.ajax({
//路径为$('#calc_list')的data-url属性值
url:$calc_list.attr('data-url'),
//提交方式为post
type:'post',
//带参:log_id为$('#calc_list')的rel属性值,tran_type为参数type
data:{log_id:$calc_list.attr('rel'),tran_type:type},
//执行回调函数,方法执行成功后调用的方法
success:function(json){
//解析json字符串为json格式
eval('var ary='+json+';');
//判断返回的ary的code值如果等于4
if(ary.code==4){
//弹框ary.msg
alert(ary.msg);
onproc = false;
//判断返回的ary的code值如果等于50
}else if(ary.code==50){
//alert(ary.msg);
//跳转页面,路径为'index.php?pluginid=money&con=wap&act=count'
window.location.href = 'index.php?pluginid=money&con=wap&act=count';
}else {
var ary_tran_type = new Array(); //新建数组
ary_tran_type[0] = '+0'; //分别给数组赋值
ary_tran_type[1] = '+666';
ary_tran_type[2] = '+888';
ary_tran_type[3] = '-555';
ary_tran_type[4] = '-333';
//删除obj中的p标签的Class:buttom-my2并添加新的class:buttom-my1
$(obj).find('p').removeClass('buttom-my2').addClass('buttom-my1');
//赋值给$('#w_rank')
$('#w_rank').text(ary.w_rank);
$('#t_rank').text(ary.t_rank);
$('#log_credit').text(ary.credit);
$('#tran_name').text(ary.tran_name);
//判断如果ary.tran_type>2返回'人品堪忧',否则返回'人品极好' 等于if else另一种写法
$('#f_text').text(ary.tran_type>2? '人品堪忧' : '人品极好');
//根据ary.tran_type的值取ary_tran_type数组中的坐标值(如ary.tran_type=2,则返回ary_tran_type[2]:+888)
$('#tran_result').text(ary_tran_type[ary.tran_type]);
$('#calc_1').addClass('disn'); //添加Class:disn
$('#calc_2').removeClass('disn');//删除Class:disn
}
}
});
}
}