练习

// JavaScript Document
/* 2013-11-1 */
/*
*Author:pangzimin
*qq:26983075
*/

var i = 0;

function utab(value){
	var sDisplay = $('#ucate ul').eq(value).css('display');
	if(sDisplay == 'none'){
		$('#ucate ul').eq(value).slideDown();
		$('#ucate h1').eq(value).find('img').attr('src','images/user_up.gif');
	}else{
		$('#ucate ul').eq(value).slideUp();
		$('#ucate h1').eq(value).find('img').attr('src','images/user_down.gif');
	}
}

function selectAll(checkbox){
	$('.goodslist').find('input[type=checkbox]').attr('checked',$(checkbox).attr('checked'));
}

function showStartPage(){
	$('.userc_myorder').add('.userc_myAddress').add('.userc_myCollection').add('.userc_myBrowse').add('.userc_content').hide();
	$('.userc_accountInfo').add('.userc_accountSafe').add('.userc_accountBalance').add('.userc_record').add('.userc_myCredit').add('.userc_myComment').add('.userc_redEnvelope').hide();
	$('#changestitle').html('用户中心');
	$('.userc_content').show();
	$('#orderCenterList li').find('a').removeClass('leftlisthover');
	$('#accountCenterList li').find('a').removeClass('leftlisthover');
}

function closeOrderState(){
	$('.orderstate').hide();
}

$(function() {
	//调试
	/*$('.userc_myorder').add('.userc_myAddress').add('.userc_myCollection').add('.userc_myBrowse').add('.userc_content').hide();
	$('.userc_accountInfo').add('.userc_accountSafe').add('.userc_accountBalance').add('.userc_record').add('.userc_myCredit').add('.userc_myComment').add('.userc_redEnvelope').hide();
	$('.userc_myComment').show();*/
	
	
	var oPic = $('#slider_pic').find('ul');
	var oImg = oPic.find('li');
	var oLen = oImg.length;
	var oLi = oImg.width();
	var prev = $("#prev");
	var next = $("#next");
	
	$('#ucate h1').hover(function (){
		$(this).css('background','#f1f1f1');
	}, function (){
		$(this).css('background','#f9f9f9');
	});
	
	//我的订单
	$('.tooltip').hover(function (){
		
		var index = $(this).parent().parent().index();
		var oState = $('.allorderlist table tr').eq(index).find('.orderstate');
		oState.show();
		
	}, function (){
		var index = $(this).parent().parent().index();
		var oState = $('.allorderlist table tr').eq(index).find('.orderstate');
		oState.hide();	
	});
	
	//起始页无收藏商品设置
	if(oLen == 0){
		$('#slider_pic').html('<span><b>您暂时没有收藏商品!</b>去<a href="#">首页</a>看看!</span>');
	}else{
		oPic.find('li').hover(function (){
			$(this).find('img:first').css('border-color','#ff3333');
		}, function (){
			$(this).find('img:first').css('border-color','#dcdcdc');
		});	
	}
	
	//订单状态
	$('.tracktit a').click(function (){
		var index = $(this).index();
		$('.tracktit a').removeClass('active');
		$(this).addClass('active');
		if(index == 0){
			$('#ordertrack .tabcon').eq(1).addClass('hide');
			$('#ordertrack .tabcon').eq(0).removeClass('hide');
		}else{
			$('#ordertrack .tabcon').eq(0).addClass('hide');
			$('#ordertrack .tabcon').eq(1).removeClass('hide');
		}
	});
	
	//我的评论
	var oCommentList = $('.commentlistinfo .showcommentbt');
	oCommentList.click(function (){
		
		var iCommentIndex = $(this).parent().parent().index();
		
		if($(this).parent().parent().find('.docomment').css('display') == 'none'){
			
			$(this).parent().parent().find('.docomment').slideDown();
			$(this).find('b').attr('class','icon_hide');
		}else{
			$(this).parent().parent().find('.docomment').slideUp();
			$(this).find('b').attr('class','icon_show');
		}
		
	});
	
	//账户信息
	var oTelVerified = $('#telVerified');
	var oEmailVerified = $('#emailVerified');
	if(oTelVerified.attr('verified') == 'true'){
		$('#accountTel').add('#verTel').hide();
		oTelVerified.find('.verified').show();
	}else{
		$('#accountTel').add('#verTel').show();
		oTelVerified.find('.verified').hide();
	}
	if(oEmailVerified.attr('verified') == 'true'){
		$('#accountEmail').add('#verEmail').hide();
		oEmailVerified.find('.verified').show();
	}else{
		$('#accountEmail').add('#verEmail').show();
		oEmailVerified.find('.verified').hide();
	}
	
	//我的红包
	$('.redEnvelope_list .redEnvelope_listtitle:first').css('background','url(images/usercenter/usercenter_19.jpg) no-repeat').css('color','#d21919');
	$('.redEnvelope_list .redEnvelope_listcon:first').css('display','block');
	$('.redEnvelope_list .redEnvelope_listtitle').click(function (){
		var index = $(this).index();
		$('.redEnvelope_list .redEnvelope_listtitle').css('background','url(images/usercenter/usercenter_18.jpg) no-repeat').css('color','#666666');;
		$('.redEnvelope_list .redEnvelope_listcon').css('display','none');
		$('.redEnvelope_list .redEnvelope_listcon').eq(index).css('display','block');
		$(this).css('background','url(images/usercenter/usercenter_19.jpg) no-repeat').css('color','#d21919');;
	});
	
	//收货地址
	var defaultAddress = $('.defaultaddress');
	defaultAddress.find('font').html('(默认送货方式)').show();
	defaultAddress.find('.setdefault').hide();
	defaultAddress.find('.deladdress').hide();
	var oAddressVessel = $('.addressVessel');
	$('.editaddress').click(function (){
		
		var oEditTable = oAddressVessel.eq($(this).index()).find('.addressc table');
		addAddress();
		
	});
	//收货地址表单验证
	$('#btnDoSaveAddress').click(function (){
		var bThrough = true;
		
		var userName = jQuery.trim($('#userName').val());
		var selCountries = jQuery.trim($('#selCountries').val());
		var selProvinces = jQuery.trim($('#selProvinces').val());
		var selCities = jQuery.trim($('#selCities').val());
		var userAddressInfo = jQuery.trim($('#userAddressInfo').val());
		var zipCode = jQuery.trim($('#zipCode').val());
		var userPhone = jQuery.trim($('#userPhone').val());
		var userTel = jQuery.trim($('#userTel').val());
		var userEmail = jQuery.trim($('#userEmail').val());
		
		//为空验证
		if(userName == ''){
			tipFun($('#userNameTip'),'收货人姓名不能为空','red');
			bThrough = false;
		}else{
			tipFun($('#userNameTip'),' ','#3a3a3a');
		}
		if(selCountries == 0 || selProvinces == 0 || selCities == 0){
			tipFun($('#userAddressTip'),'请选择详细地址','red');
			bThrough = false;
		}else{
			tipFun($('#userAddressTip'),'','#3a3a3a');
		}
		if(userAddressInfo == ''){
			tipFun($('#addressInfoTip'),'请填写详细地址','red');
			bThrough = false;
		}else{
			tipFun($('#addressInfoTip'),'(填写详细地址有助于快速配送)','#3a3a3a');
		}
		if(userPhone == '' && userTel == ''){
			tipFun($('#telTip'),'请填写联系电话或固定电话','red');
			bThrough = false;
		}else{
			tipFun($('#telTip'),'','#3a3a3a');
		}
		if(userEmail == ''){
			//暂无
			tipFun($('#EmailTip'),'(用来接收订单提醒邮件,便于您及时了解订单状态)','#3a3a3a');
		}else{
			tipFun($('#EmailTip'),'(用来接收订单提醒邮件,便于您及时了解订单状态)','#3a3a3a');
		}
		if(zipCode == ''){
			//暂无
			tipFun($('#zipCodeTip'),' ','#3a3a3a');
		}else{
			tipFun($('#zipCodeTip'),' ','#3a3a3a');
		}
		
		//非法字符验证
		if(!illegalStr(userName)){
			tipFun($('#userNameTip'),'收货人姓名含有非法字符','red');
			bThrough = false;
		}
		if(!illegalStr(userAddressInfo)){
			tipFun($('#addressInfoTip'),'详细地址含有非法字符','red');
			bThrough = false;
		}
		if(!illegalStr(userPhone) || !illegalStr(userTel)){
			tipFun($('#telTip'),'联系电话或固定电话含有非法字符','red');
			bThrough = false;
		}
		if(!illegalStr(userEmail)){
			tipFun($('#EmailTip'),'邮箱含有非法字符','red');
			bThrough = false;
		}
		if(!illegalStr(zipCode)){
			tipFun($('#zipCodeTip'),'邮政编码含有非法字符','red');
			bThrough = false;
		}else{
			tipFun($('#zipCodeTip'),' ','#3a3a3a');
		}
		
		//联系方式验证	
		if(userPhone != ''){
			if(!checkTel(userPhone)){
				tipFun($('#telTip'),'联系电话或固定电话格式不正确','red');
				bThrough = false;
			}else{
				tipFun($('#telTip'),'','#3a3a3a');
			}
		}
		if(userTel != ''){
			if(!checkTel(userTel)){
				tipFun($('#telTip'),'联系电话或固定电话格式不正确','red');
				bThrough = false;
			}else{
				tipFun($('#telTip'),'','#3a3a3a');
			}
		}
		
		//邮箱验证
		if(userEmail != ''){
			if(!checkEmail(userEmail)){
				tipFun($('#EmailTip'),'邮箱格式不正确','red');
				bThrough = false;
			}else{
				tipFun($('#EmailTip'),'(用来接收订单提醒邮件,便于您及时了解订单状态)','#3a3a3a');
			}
		}
		
		//邮政编码验证	
		if(zipCode != ''){
			if(!isPostalCode(zipCode)){
				tipFun($('#zipCodeTip'),'邮政编码格式不正确','red');
				bThrough = false;
			}
		}
		
	});
	
	//邮政编码验证函数
	function isPostalCode(s)
	{
		var patrn=/^[a-zA-Z0-9 ]{3,12}$/;
		if (!patrn.exec(s)) return false
		return true
	}
	
	//邮箱验证函数
	function checkEmail(value){
		var b = true;
		var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
		if(!myreg.test(value))
		{
			b = false;
	   	}
		
		return b;
	}
	
	//联系方式验证函数
	function checkTel(tel)
	{
	   var mobile = /^1[3|5|8]\d{9}$/ , phone = /^0\d{2,3}-?\d{7,8}$/;
	   return mobile.test(tel) || phone.test(tel);
	}
	
	//非法字符验证函数
	function illegalStr(keywords){
		var reg2="~`<>!@#$%^&*()-+/'";
		var b = true;
		for(var i=0;i<keywords.length; i++)
		{
		  var temp=keywords.substring(i,i+1);
		  if(reg2.indexOf(temp)>-1)
		  {
			b = false;
		  }
		}
		return b;
	}
	
	//我的收藏
	$('#recenthistory li .time .dot').css('opacity',0.4);
	var productlist = $('#recenthistory li');
	var firstg = 0;
	productlist.each(function(index, element) {
		if(productlist.eq(index).find('.title').html() == '更早'){
			if(firstg == 0){firstg = index;}
			if(index > firstg){
				productlist.eq(index).find('.title').css('background','none').html('');
			}
		}
    });
	
	productlist.hover(function (){
		$(this).find('.date').stop().animate({top:"62px"});
		$(this).find('.dot').stop().animate({top:"66px",opacity:1});
		$(this).find('.delet').show();
	}, function (){
		$(this).find('.date').stop().animate({top:"46px"});
		$(this).find('.dot').stop().animate({top:"50px",opacity:0.4});
		$(this).find('.delet').hide();
	});
	
	//我的收藏页无收藏商品设置
	//alert($('.userc_myCollection ul .goodslist').length);
	if($('.userc_myCollection ul .goodslist').length == 0){
		$('.userc_myCollection ul').html('<span class="nogoods"><img src="images/usercenter/usercenter_9.jpg" />您暂时没有暂存商品  去<a href="#">首页</a>逛逛!</span>').css('border','none');
	}
	
	oPic.width(oLen * 185);
	oPic.width();
	var iNow = 0;
	var iTimer = null;
	prev.click(function() {
		if (iNow > 0) {
			iNow--;

		}
		ClickScroll();
	})
	next.click(function() {
		if (iNow < oLen - 4) {
			iNow++
		}
		ClickScroll();
	})

	function ClickScroll() {

		//iNow == 0 ? prev.addClass('no_click') : prev.removeClass('no_click');
		//iNow == oLen - 4 ? next.addClass("no_click") : next.removeClass("no_click");

		oPic.animate({
			left: -iNow * 185
		})
	}
	
	//遍历收藏商品的评论等级
	for(i = 0;i < $('.goodsAssess').length;i++){
		var grade = $('.goodsAssess').eq(i).attr('grade');
		$('.goodsAssess').eq(i).width(grade*14);
	}
	
	//订单中心列表
	$('#orderCenterList li').click(function (){
		$('.userc_myorder').add('.userc_myAddress').add('.userc_myCollection').add('.userc_myBrowse').add('.userc_content').hide();
		$('.userc_accountInfo').add('.userc_accountSafe').add('.userc_accountBalance').add('.userc_record').add('.userc_myCredit').add('.userc_myComment').add('.userc_redEnvelope').hide();
		$('#orderCenterList li').find('a').removeClass('leftlisthover');
		$('#accountCenterList li').find('a').removeClass('leftlisthover');
		$(this).find('a').addClass('leftlisthover');
		$('#changestitle').html($(this).find('a').html());
		switch($(this).index()){
			case 0:
				
				$('.userc_myorder').show();
				
				break;
			case 1:
				$('.userc_myAddress').show();
				break;
			case 2:
				$('.userc_myCollection').show();
				break;
			case 3:
				$('.userc_myBrowse').show();
				break;
		}
	});
	
	//账户中心列表
	$('#accountCenterList li').click(function (){
		$('.userc_myorder').add('.userc_myAddress').add('.userc_myCollection').add('.userc_myBrowse').add('.userc_content').hide();
		$('.userc_accountInfo').add('.userc_accountSafe').add('.userc_accountBalance').add('.userc_record').add('.userc_myCredit').add('.userc_myComment').add('.userc_redEnvelope').hide();
		$('#orderCenterList li').find('a').removeClass('leftlisthover');
		$('#accountCenterList li').find('a').removeClass('leftlisthover');
		$(this).find('a').addClass('leftlisthover');
		$('#changestitle').html($(this).find('a').html());
		switch($(this).index()){
			case 0:
				$('.userc_accountInfo').show();
				break;
			case 1:
				$('.userc_accountSafe').show();
				break;
			case 2:
				$('.userc_accountBalance').show();
				break;
			case 3:
				$('.userc_record').show();
				break;
			case 4:
				$('.userc_myCredit').show();
				break;
			case 5:
				$('.userc_myComment').show();
				break;
			case 6:
				$('.userc_redEnvelope').show();
				break;
		}
	});
	
	function tipFun(obj,str,color){
		obj.html(str).css('color',color).show();
	}

});

function addAddress(){
	showBg();
}

function getTop(e){
	var offset=e.offsetTop;
	if(e.offsetParent!=null) offset+=getTop(e.offsetParent);
	return offset;
}

function getLeft(e){
	var offset=e.offsetLeft;
	if(e.offsetParent!=null) offset+=getLeft(e.offsetParent);
	return offset;
} 

function closead(){
	$("#fullbg").hide();
	$("#addressInfo").hide();
}

function showBg() {
	$("#fullbg").show();
	$("#fullbg").height(window.screen.height);
	$("#addressInfo").css('left',($('body').width()-$("#addressInfo").width())/2);
	$("#addressInfo").css('top','20%');
	$("#addressInfo").show();
}

function showCashWay(){
	$('.cashway').show();;
}
function closeCashWay(){
	$('.cashway').hide();;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值