XXXXX
C/C++
XXXXX
C#/.net
XXXXX
js
java
java
开发导航 开发导航 www.endv.cn
天云

js 特效

 

 

 

 

 

 

 

 下拉菜单

复制代码
 1 <script type="text/javascript"> 
 2 function displaySubMenu(li) { 
 3 var subMenu = li.getElementsByTagName("ul")[0]; 
 4 subMenu.style.display = "block"; 
 5 } 
 6 function hideSubMenu(li) { 
 7 var subMenu = li.getElementsByTagName("ul")[0]; 
 8 subMenu.style.display = "none"; 
 9  // e.getElementsByClassName("i").length
10  
11 } 
12 </script> 
13   
复制代码

 

 

复制代码
  1  
  2 <style type="text/css"> 
  3 * { 
  4 padding:0; 
  5 margin:0; 
  6 } 
  7 body { 
  8 font-family:verdana, sans-serif; 
  9 font-size:small; 
 10 } 
 11 #navigation, #navigation li ul { 
 12 list-style-type:none; 
 13 } 
 14 #navigation { 
 15 margin:20px; 
 16 } 
 17 #navigation li { 
 18 float:left; 
 19 text-align:center; 
 20 position:relative; 
 21 } 
 22 #navigation li a:link, #navigation li a:visited { 
 23 display:block; 
 24 text-decoration:none; 
 25 color:#000; 
 26 width:120px; 
 27 height:40px; 
 28 line-height:40px; 
 29 border:1px solid #fff; 
 30 border-width:1px 1px 0 0; 
 31 background:#c5dbf2; 
 32 padding-left:10px; 
 33 } 
 34 #navigation li a:hover { 
 35 color:#fff; 
 36 background:#2687eb; 
 37 } 
 38 #navigation li ul li a:hover { 
 39 color:#fff; 
 40 background:#6b839c; 
 41 } 
 42 #navigation li ul { 
 43 display:none; 
 44 position:absolute; 
 45 top:40px; 
 46 left:0; 
 47 margin-top:1px; 
 48 width:120px; 
 49 } 
 50 #navigation li ul li ul { 
 51 display:none; 
 52 position:absolute; 
 53 top:0px; 
 54 left:130px; 
 55 margin-top:0; 
 56 margin-left:1px; 
 57 width:120px; 
 58 } 
 59 </style> 
 60 <script type="text/javascript"> 
 61 function displaySubMenu(li) { 
 62 var subMenu = li.getElementsByTagName("ul")[0]; 
 63 subMenu.style.display = "block"; 
 64 } 
 65 function hideSubMenu(li) { 
 66 var subMenu = li.getElementsByTagName("ul")[0]; 
 67 subMenu.style.display = "none"; 
 68  // e.getElementsByClassName("i").length
 69  
 70 } 
 71 </script> 
 72   
 73 <ul id="navigation"> 
 74 <li onmouseover="displaySubMenu(this)" onmouseout="hideSubMenu(this)"> 
 75 <a href="#">栏目1</a> 
 76 <ul> 
 77 <li><a href="#">栏目1->菜单1</a></li> 
 78 <li><a href="#">栏目1->菜单2</a></li> 
 79 <li><a href="#">栏目1->菜单3</a></li> 
 80 <li><a href="#">栏目1->菜单4</a></li> 
 81 </ul> 
 82 </li> 
 83 <li onmouseover="displaySubMenu(this)" onmouseout="hideSubMenu(this)"> 
 84 <a href="#">栏目2</a> 
 85 <ul> 
 86 <li><a href="#">栏目2->菜单1</a></li> 
 87 <li><a href="#">栏目2->菜单2</a></li> 
 88 <li><a href="#">栏目2->菜单3</a></li> 
 89 <li><a href="#">栏目2->菜单4</a></li> 
 90 <li><a href="#">栏目2->菜单5</a></li> 
 91 </ul> 
 92 </li> 
 93 <li onmouseover="displaySubMenu(this)" onmouseout="hideSubMenu(this)"> 
 94 <a href="#">栏目3</a> 
 95 <ul> 
 96 <li onmouseover="displaySubMenu(this)" onmouseout="hideSubMenu(this)"> 
 97 <a href="#">栏目3->菜单1</a> 
 98 <ul> 
 99 <li><a href="#">菜单1->子菜单1</a></li> 
100 <li><a href="#">菜单1->子菜单2</a></li> 
101 <li><a href="#">菜单1->子菜单3</a></li> 
102 <li><a href="#">菜单1->子菜单4</a></li> 
103 </ul> 
104 </li> 
105 <li><a href="#">栏目3->菜单2</a></li> 
106 <li onmouseover="displaySubMenu(this)" onmouseout="hideSubMenu(this)"> 
107 <a href="#">栏目3->菜单3</a> 
108 <ul> 
109 <li><a href="#">菜单3->子菜单1</a></li> 
110 <li><a href="#">菜单3->子菜单2</a></li> 
111 <li><a href="#">菜单3->子菜单3</a></li> 
112 </ul> 
113 </li> 
114 </ul> 
115 </li> 
116 </ul> 
117   
View Code
复制代码

 

 

 

复制代码
  1 var wait, is_submit=0,tipspage;;
  2 var login_url,reg_url,logout_url,member_url,cart_url,delcart_url;
  3 var regexEnum = 
  4 {
  5     intege:"/^-?[1-9]\\d*$/",                    //整数
  6     intege1:"/^[1-9]\\d*$/i",                    //正整数
  7     intege2:"/^-[1-9]\\d*$/i",                    //负整数
  8     num:"/^([+-]?)\\d*\\.?\\d+$/i",            //数字
  9     num1:"/^[1-9]\\d*|0$/i",                    //正数(正整数 + 0)
 10     num2:"/^-[1-9]\\d*|0$/i",                    //负数(负整数 + 0)
 11     decmal:"/^([+-]?)\\d*\\.\\d+$/i",            //浮点数
 12     decmal1:"/^[1-9]\\d*.\\d*|0.\\d*[1-9]\\d*$/i",      //正浮点数
 13     decmal2:"/^-([1-9]\\d*.\\d*|0.\\d*[1-9]\\d*)$/i",  //负浮点数
 14     decmal3:"/^-?([1-9]\\d*.\\d*|0.\\d*[1-9]\\d*|0?.0+|0)$/i",  //浮点数
 15     decmal4:"/^[1-9]\\d*.\\d*|0.\\d*[1-9]\\d*|0?.0+|0$/i",   //非负浮点数(正浮点数 + 0)
 16     decmal5:"/^(-([1-9]\\d*.\\d*|0.\\d*[1-9]\\d*))|0?.0+|0$/i",  //非正浮点数(负浮点数 + 0)
 17 
 18     email:"/^\\w+((-\\w+)|(\\.\\w+))*\\@[A-Za-z0-9]+((\\.|-)[A-Za-z0-9]+)*\\.[A-Za-z0-9]+$/i", //邮件
 19     color:"/^[a-fA-F0-9]{6}$/i",                //颜色
 20     url:"^/http[s]?:\\/\\/([\\w-]+\\.)+[\\w-]+([\\w-./?%&=]*)?$/i",    //url
 21     chinese:"/^[\\u4E00-\\u9FA5\\uF900-\\uFA2D]+$/i",                    //仅中文
 22     ascii:"/^[\\x00-\\xFF]+$/i",                //仅ACSII字符
 23     zipcode:"/^\\d{6}$/i",                        //邮编
 24     mobile:"/^(1)[0-9]{10}$/i",                //手机
 25     ip4:"/^(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)\\.(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)\\.(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)\\.(25[0-5]|2[0-4]\\d|[0-1]\\d{2}|[1-9]?\\d)$/i",    //ip地址
 26     notempty:"/^\\S+$/i",                        //非空
 27     picture:"/(.*)\\.(jpg|bmp|gif|ico|pcx|jpeg|tif|png|raw|tga)$/i",    //图片
 28     rar:"/(.*)\\.(rar|zip|7zip|tgz)$/i",                                //压缩文件
 29     date:"/^\\d{4}(\\-|\\/|\.)\\d{1,2}\\1\\d{1,2}$/i",                    //日期
 30     qq:"/^[1-9]*[1-9][0-9]*$/i",                //QQ号码
 31     tel:"/^(([0\\+]\\d{2,3}-)?(0\\d{2,3})-)?(\\d{7,8})(-(\\d{3,}))?$/i",    //电话号码的函数(包括验证国内区号,国际区号,分机号)
 32     username:"/^\\w+$/i",                        //用来用户注册。匹配由数字、26个英文字母或者下划线组成的字符串
 33     letter:"/^[A-Za-z]+$/i",                    //字母
 34     letter_u:"/^[A-Z]+$/i",                    //大写字母
 35     letter_l:"/^[a-z]+$/i",                    //小写字母
 36     idcard:"/^[1-9]([0-9]{14}|[0-9]{17})$/i",    //身份证
 37     pwd:"/[0-9|A-Z|a-z]{6,16}/i",                //密码只由数字或者数字组成
 38     ps_username:"/^[\\u4E00-\\u9FA5\\uF900-\\uFA2D_\\w]+$/i" //中文、字母、数字 _
 39 }
 40 function ugetcookie(sName) {
 41     var aCookie = document.cookie.split('; ');
 42     for (var i=0; i < aCookie.length; i++) {
 43         var aCrumb = aCookie[i].split('=');
 44         if (sName == aCrumb[0])
 45         return decodeURI(aCrumb[1]);
 46      }
 47     return '';
 48 }
 49 
 50 function delImg(obj){
 51     $(obj).parents(".uploadfile").find(".preview").html('');
 52     $(obj).parents(".uploadfile").find(".deleteuploadparent").hide();
 53     $(obj).parents(".uploadfile").find('input[@type="file"]').val("");
 54     $(obj).parents(".uploadfile").find(".input-val").val("");
 55 }
 56 
 57 function delImgs(obj){
 58     $(obj).parents("li").remove();
 59 }
 60 
 61 function appendImg(obj, jsondata){
 62     $(obj).parents("form").find(".imagelist").append('<li class="per-20"><input type="hidden" name="imgs[]" value="'+jsondata.thumb+'"><i class="deleteimg" onclick="delImgs(this);"></i><img src="'+jsondata.thumb+'" class="col-11 border"></li>');
 63 }
 64 
 65 function checkImg(obj){
 66     var imgnum = $(obj).parents("form").find(".imagelist li").length;
 67     if(imgnum>4){
 68         error("最多只能上传5张图片!");
 69         return false;
 70     }else{
 71         return true;
 72     }
 73 }
 74 
 75 function showImg(obj, jsondata){
 76     $(obj).parents(".uploadfile").find(".preview").html('<img src="'+jsondata.thumb+'">');
 77     $(obj).parents(".uploadfile").find(".deleteuploadparent").show();
 78     $(obj).parents(".uploadfile").find(".input-val").val(jsondata.thumb);
 79 }
 80 
 81 function uploadfiles(obj){
 82     var fd = new FormData();
 83     fd.append("upload", $(obj).get(0).files[0]);
 84     $.ajax({
 85         url: "/index.php/site/attachment/attachments/ajaxupload/",
 86         type: "POST",
 87         dataType: "json",
 88         processData: false,
 89         contentType: false,
 90         data: fd,
 91         success: function(rs) {
 92             $(obj).parents(".uploadfile").find(".preview").html('');
 93             var afterfun = $(obj).attr("data-after");
 94             if(afterfun){
 95                 eval(afterfun+"(obj, rs.data);");
 96             }
 97         }
 98     });
 99 }
100 
101 function countSize(size){
102     return parseInt(size/1024);
103 }
104 
105 function centerHtml(idobj){
106     var pagewin = layer.open({
107       type: 1,
108       shade: true,
109       closeBtn: 0,
110       area: ['400px', 'auto'], 
111       title: false,
112       shade: 0.2,
113       content: $('#'+idobj)
114     });
115     $(document.body).addClass("forbidscroll");
116     $(".closewin").click(function(){
117         layer.close(pagewin);
118         layer.close(tipspage);
119         $(document.body).removeClass("forbidscroll");
120     });
121 }
122 
123 function previewImage(file, minsize, maxsize){
124     var beforefun = $(file).attr("data-before");
125     if(beforefun){
126         var rs = eval(beforefun+"(file);");
127         if(!rs){
128             return false;
129         }
130     }
131     minsize = minsize?minsize:100;
132     maxsize = maxsize?maxsize:3000;
133     var filesize = countSize(file.files[0].size);
134     if(filesize>maxsize || filesize<minsize){
135         error("上传图片不能大于"+maxsize+"KB且不能小于"+minsize+"KB");
136         $(file).prev().html('');
137         return false;
138     }
139     var MAXWIDTH  = $(file).parent().width(); 
140     var MAXHEIGHT = $(file).parent().height();
141     var divobj = $(file).prev().get(0);
142     if (file.files && file.files[0])
143     {
144       divobj.innerHTML ='<em class="loading"></em><img>';
145       var img = $(file).prev().find("img").get(0);
146       img.onload = function(){
147         var rect = clacImgZoomParam(MAXWIDTH, MAXHEIGHT, img.offsetWidth, img.offsetHeight);
148         //img.width  =  rect.width;
149         //img.height =  rect.height;
150         //img.style.marginTop = rect.top+'px';
151       }
152       var reader = new FileReader();
153       reader.onload = function(evt){img.src = evt.target.result;}
154       reader.readAsDataURL(file.files[0]);
155         
156     }
157     else //兼容IE
158     {
159     var sFilter='filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale,src="';
160     file.select();
161     var src = document.selection.createRange().text;
162      divobj.innerHTML ='<em class="loading"></em><img style="width:50px;height:50px;">';
163     var img = $(file).prev().find("img").get(0);
164     img.filters.item('DXImageTransform.Microsoft.AlphaImageLoader').src = src;
165     //var rect = clacImgZoomParam(MAXWIDTH, MAXHEIGHT, img.offsetWidth, img.offsetHeight);
166     //status =('rect:'+rect.top+','+rect.left+','+rect.width+','+rect.height);
167     //div.innerHTML = "<div id=divhead style='width:"+rect.width+"px;height:"+rect.height+"px;margin-top:"+rect.top+"px;"+sFilter+src+"\"'></div>";
168     }
169     uploadfiles(file);
170 }
171 function clacImgZoomParam( maxWidth, maxHeight, width, height ){
172     var param = {top:0, left:0, width:width, height:height};
173     if( width>maxWidth || height>maxHeight )
174     {
175         rateWidth = width / maxWidth;
176         rateHeight = height / maxHeight;
177          
178         if( rateWidth > rateHeight )
179         {
180             param.width =  maxWidth;
181             param.height = Math.round(height / rateWidth);
182         }else
183         {
184             param.width = Math.round(width / rateHeight);
185             param.height = maxHeight;
186         }
187     }
188      
189     param.left = Math.round((maxWidth - param.width) / 2);
190     param.top = Math.round((maxHeight - param.height) / 2);
191     return param;
192 }
193 
194 
195 function time() {
196     if (wait == 0) {
197         $("#sendcode").attr("disabled", false);
198         $("#sendcode").removeClass("disabled");
199         $("#sendcode").val("获取验证码");
200         wait = 90;
201     } else {
202         $("#sendcode").attr("disabled", true);
203         $("#sendcode").addClass("disabled");
204         $("#sendcode").html("重新发送(" + wait + ")");
205         wait--;
206         setTimeout(function(){
207             time()
208         },1000)
209     }
210 }
211 
212 function sendcode(){
213     wait = 90;
214     time(90);
215 }
216 
217 function error(msg, times){
218     times = times?times:3;
219     times = times*1000;
220     layer.msg(msg, {time: times, icon:5});
221 }
222 
223 function right(msg, times){
224     times = times?times:3;
225     times = times*1000;
226     layer.msg(msg, {time: times, icon:6});
227 }
228 
229 function load(){
230     layer.load(1, {
231       shade: [0.8,'#000']
232     });
233 }
234 
235 function loadajaxHtml(url, param, id) {
236     $.ajax({
237         cache: true,
238         type: "POST",
239         dataType: "html",
240         url:url,
241         data:param,
242         async: false,
243         error: function(request) {
244             error("由于网络问题无法请求服务器数据,请刷新页面试试!");
245         },
246         success: function(result){
247             $("#"+id).html(result);
248         }
249     });
250 }
251 
252 function getCart(){
253     loadajaxHtml(cart_url, '', "cartbox");
254 }
255 
256 function delCart(obj_id){
257     loadajax(delcart_url, "obj_id="+obj_id, "getCart");
258 }
259 
260 function blurajax(url, param, obj) {
261     $.ajax({
262         cache: true,
263         type: "POST",
264         dataType: "json",
265         url:url,
266         data:param,
267         async: false,
268         error: function(request) {
269             error("由于网络问题无法请求服务器数据,请刷新页面试试!");
270         },
271         success: function(rs){
272             layer.closeAll();
273             if(rs.error){
274                 $(obj).attr("data-pass", "false");
275                 $("#"+$(obj).attr("data-id")+"_error").show();
276                 $("#"+$(obj).attr("data-id")+"_error").html($(obj).attr("data-ajax-error"));
277                 if(obj){
278                     $(obj).parent().find(".right").hide();
279                 }
280             }else{
281                 $(obj).attr("data-pass", "true");
282                 $("#"+$(obj).attr("data-id")+"_error").hide();
283                 $(obj).parent().find(".right").show();
284             }
285         }
286     });
287 }
288     
289 function loadajax(url, param, fun) {
290     $.ajax({
291         cache: true,
292         type: "POST",
293         dataType: "json",
294         url:url,
295         data:param,
296         async: false,
297         error: function(request) {
298             error("由于网络问题无法请求服务器数据,请刷新页面试试!");
299         },
300         success: function(rs){
301             layer.closeAll();
302             if(rs.error){
303                 if(fun){
304                     eval(fun+"(rs);");
305                 }else{
306                     error(rs.error);
307                 }
308             }else{
309                 if(rs.message && rs.message!="hide"){
310                     right(rs.message);
311                 }
312                 if(fun){
313                     eval(fun+"(rs);");
314                 }
315                 if(rs.redirect) {
316                     setTimeout(function(){
317                         if(rs.redirect=="reload"){
318                             window.location.reload();
319                         }else{
320                             location.href=rs.redirect;
321                         }
322                     }, 500);
323                 }
324             }
325         }
326     });
327 }
328 
329 function ajaxSubmit(e) {
330     var form = e;
331     var afterfun = $(form).attr("data-after");
332     var beforefun = $(form).attr("data-before");
333     if(beforefun){
334         var rs = eval(beforefun+"(form);");
335         if(!rs){
336             return false;
337         }
338     }
339     load();
340     if(is_submit==1){
341         error("提交信息中,请等待...");
342     }
343     is_submit = 1;
344     $.ajax({
345         cache: true,
346         type: "POST",
347         dataType: "json",
348         url:form.action,
349         data:$(form).serialize(),
350         async: false,
351         error: function(request) {
352             error("由于网络问题无法请求服务器数据,请刷新页面试试!");
353         },
354         success: function(rs){
355             $(document.body).removeClass("forbidscroll");
356             layer.closeAll();
357             is_submit = 0;
358             if(rs.error){
359                 error(rs.error);
360             }else{
361                 if(rs.message && rs.message!="hide"){
362                     right(rs.message);
363                 }
364                 if(afterfun){
365                     eval(afterfun+"(rs);");
366                 }
367                 if(rs.redirect) {
368                     setTimeout(function(){
369                         if(rs.redirect=="reload"){
370                             window.location.reload();
371                         }else{
372                             location.href=rs.redirect;
373                         }
374                     }, 500);
375                 }
376             }
377         }
378     });
379 }
380 
381 $(document).ready(function() {
382     if(ugetcookie('nickname')){
383         $("#login_status").html('<a href="'+member_url+'"><span style="width:70px;overflow:hidden;display:inline-block;float:left;white-space: nowrap;text-overflow: ellipsis;text-align:right;color:#ff0000;">'+ugetcookie('nickname')+'</span></a> <a href="'+logout_url+'">【退出】</a>');
384     }else{
385         $("#login_status").html('<a href="'+login_url+'"><span class="text-red">亲,请登录</span></a> <a href="'+reg_url+'"><span class="margin-left-5">免费注册</span></a>');
386         
387     }
388     
389     $("input[type='checkbox']").click(function(){
390         if($(this).prop("checked")==true && $(this).attr("data-id")){
391             $("#"+$(this).attr("data-id")+"_error").hide();
392         }
393     });
394     
395     $(document).on("blur", '.blurevent', function () {
396         var obj  = this;
397         if($(obj).attr("data-required")=="true" && !$.trim($(obj).val())){
398             var error_msg = $(obj).attr("data-empty")?$(obj).attr("data-empty"):$(obj).attr("data-error");
399             if($(obj).attr("data-type")=="tips"){
400                 tipspage = layer.tips(error_msg, obj, {tips: [1, '#e62129'], time:300000});
401             }else{
402                 $("#"+$(obj).attr("data-id")+"_error").show();
403                 $("#"+$(obj).attr("data-id")+"_error").html(error_msg);
404                 $(obj).parent().find(".right").hide();
405             }
406             return false;
407         }
408         
409         if($(obj).attr("data-reg") && $.trim($(obj).val())){
410             var reg =  eval(eval("regexEnum."+$(obj).attr("data-reg")));
411             if (!reg.test($(obj).val())) {
412                 var error_msg = $(obj).attr("data-error");
413                 if($(obj).attr("data-type")=="tips"){
414                     tipspage = layer.tips(error_msg, obj, {tips: [1, '#e62129'], time:300000});
415                 }else{
416                     $("#"+$(obj).attr("data-id")+"_error").show();
417                     $("#"+$(obj).attr("data-id")+"_error").html(error_msg);
418                     $(obj).parent().find(".right").hide();
419                 }
420                 return false;
421             }
422         }
423         
424         if($(obj).attr("data-equal")){
425             if($("#"+$(obj).attr("data-equal")).val()!=$(obj).val()){
426                 if($(obj).attr("data-type")=="tips"){
427                     tipspage = layer.tips(error_msg, obj, {tips: [1, '#e62129'], time:300000});
428                 }else{
429                     var error_msg = $(obj).attr("data-error");
430                     $("#"+$(obj).attr("data-id")+"_error").show();
431                     $("#"+$(obj).attr("data-id")+"_error").html(error_msg);
432                     $(obj).parent().find(".right").hide();
433                 }
434                 return false;
435             }
436         }
437         
438         if($(obj).attr("data-ajax")=="true"){
439             var param = $(obj).attr("name")+"="+$(obj).val()+"&times="+Math.random();
440             blurajax($(obj).attr("data-url"), param, obj);
441         }else{
442             if($(obj).attr("data-type")=="tips"){
443                 layer.close(tipspage);
444             }else{
445                 $("#"+$(obj).attr("data-id")+"_error").hide();
446             }
447             $(obj).parent().find(".right").show();
448         }
449     });
450     
451     $(document).on("submit", 'form', function () {
452         var form = this;
453         var is_bread = 0;
454         $(form).find("input").each(function(i, e){
455             if($(e).attr("type")=="text" || $(e).attr("type")=="password" || $(e).attr("type")=="hidden"){
456                 if($(e).attr("data-required")=="true" && !$.trim($(e).val())){
457                     var error_msg = $(e).attr("data-empty")?$(e).attr("data-empty"):$(e).attr("data-error");
458                     if($(e).attr("data-type")=="tips"){
459                         tipspage = layer.tips(error_msg, e, {tips: [1, '#e62129'], time: 3000});
460                     }else{
461                         $("#"+$(e).attr("data-id")+"_error").show();
462                         $("#"+$(e).attr("data-id")+"_error").html(error_msg);
463                         $(e).parent().find(".right").hide();
464                     }
465                     if($(e).attr("data-scroll")){
466                         $("html,body").animate({scrollTop:  $('#'+$(e).attr("data-scroll")).offset().top}, 300);
467                     }
468                     is_bread = 1;
469                     return false;
470                 }
471                 if($(e).attr("data-reg") && $.trim($(e).val())){
472                     var reg =  eval(eval("regexEnum."+$(e).attr("data-reg")));
473                     if (!reg.test($(e).val())) {
474                         var error_msg = $(e).attr("data-error");
475                         if($(e).attr("data-type")=="tips"){
476                             tipspage = layer.tips(error_msg, e, {tips: [1, '#e62129'], time: 3000});
477                             $(document.body).addClass("forbidscroll");
478                         }else{
479                             $("#"+$(e).attr("data-id")+"_error").show();
480                             $("#"+$(e).attr("data-id")+"_error").html(error_msg);
481                             $(e).parent().find(".right").hide();
482                         }
483                         is_bread = 1;
484                         return false;
485                     }
486                 }
487                 
488                 if($(e).attr("data-equal")){
489                     if($("#"+$(e).attr("data-equal")).val()!=$(e).val()){
490                         var error_msg = $(e).attr("data-error");
491                         if($(e).attr("data-type")=="tips"){
492                             tipspage = layer.tips(error_msg, e, {tips: [1, '#e62129'], time: 3000});
493                             $(document.body).addClass("forbidscroll");
494                         }else{
495                             $("#"+$(e).attr("data-id")+"_error").show();
496                             $("#"+$(e).attr("data-id")+"_error").html(error_msg);
497                             $(e).parent().find(".right").hide();
498                         }
499                         is_bread = 1;
500                         return false;
501                     }
502                 }
503                 
504                 if($(e).attr("data-pass")=="false"){
505                     var error_msg = $(e).attr("data-ajax-error")?$(e).attr("data-ajax-error"):$(e).attr("data-error");
506                     if($(e).attr("data-type")=="tips"){
507                         tipspage = layer.tips(error_msg, e, {tips: [1, '#e62129'], time: 3000});
508                         $(document.body).addClass("forbidscroll");
509                     }else{
510                         $("#"+$(e).attr("data-id")+"_error").show();
511                         $("#"+$(e).attr("data-id")+"_error").html(error_msg);
512                         $(e).parent().find(".right").hide();
513                     }
514                     is_bread = 1;
515                     return false;
516                 }
517                 
518                 
519             }else if($(e).attr("type")=="checkbox"){
520                 if($(e).attr("data-required")=="true" && $(e).prop("checked")==false){
521                     var error_msg = $(e).attr("data-empty")?$(e).attr("data-empty"):$(e).attr("data-error");
522                     if($(e).attr("data-type")=="tips"){
523                         tipspage = layer.tips(error_msg, e, {tips: [1, '#e62129'], time: 3000});
524                         $(document.body).addClass("forbidscroll");
525                     }else{
526                         $("#"+$(e).attr("data-id")+"_error").show();
527                         $("#"+$(e).attr("data-id")+"_error").html(error_msg);
528                         $(e).parent().find(".right").hide();
529                     }
530                     is_bread = 1;
531                     return false;
532                 }
533             }
534         });
535         if(is_bread==1){
536             return false;
537         }
538         $(form).find("textarea").each(function(i, e){
539             if($(e).attr("data-required")=="true" && !$.trim($(e).val())){
540                 var error_msg = $(e).attr("data-empty")?$(e).attr("data-empty"):$(e).attr("data-error");
541                 if($(e).attr("data-type")=="tips"){
542                     tipspage = layer.tips(error_msg, e, {tips: [1, '#e62129'], time: 3000});
543                     $(document.body).addClass("forbidscroll");
544                 }else{
545                     $("#"+$(e).attr("data-id")+"_error").show();
546                     $("#"+$(e).attr("data-id")+"_error").html(error_msg);
547                     $(e).parent().find(".right").hide();
548                 }
549                 is_bread = 1;
550                 return false;
551             }
552             if($(e).attr("data-reg") && $.trim($(e).val())){
553                 var reg =  eval(eval("regexEnum."+$(e).attr("data-reg")));
554                 if (!reg.test($(e).val())) {
555                     var error_msg = $(e).attr("data-empty")?$(e).attr("data-empty"):$(e).attr("data-error");
556                     if($(e).attr("data-type")=="tips"){
557                         tipspage = layer.tips(error_msg, e, {tips: [1, '#e62129'], time: 3000});
558                         $(document.body).addClass("forbidscroll");
559                     }else{
560                         $("#"+$(e).attr("data-id")+"_error").show();
561                         $("#"+$(e).attr("data-id")+"_error").html(error_msg);
562                         $(e).parent().find(".right").hide();
563                     }
564                     is_bread = 1;
565                     return false;
566                 }
567             }
568         });
569         if(is_bread==1){
570             return false;
571         }
572         $(form).find("select").each(function(i, e){
573             if($(e).attr("data-required")=="true" && (!$.trim($(e).val()) || $(e).val()==0)){
574                 var error_msg = $(e).attr("data-empty")?$(e).attr("data-empty"):$(e).attr("data-error");
575                 if($(e).attr("data-type")=="tips"){
576                     tipspage = layer.tips(error_msg, e, {tips: [1, '#e62129'], time: 3000});
577                 }else{
578                     $("#"+$(e).attr("data-id")+"_error").show();
579                     $("#"+$(e).attr("data-id")+"_error").html(error_msg);
580                 }
581                 if($(e).attr("data-scroll")){
582                     $("html,body").animate({scrollTop:  $('#'+$(e).attr("data-scroll")).offset().top}, 300);
583                 }
584                 is_bread = 1;
585                 return false;
586             }
587         });
588         
589         if(is_bread==1){
590             return false;
591         }
592         
593         if(is_submit==1){
594             error("正在提交数据请不要重复提交!");
595             return false;
596         }
597         if($(form).attr("jump")=="true"){
598             return true;
599         }else{
600             ajaxSubmit(form);
601             return false;
602         }
603     });
604     
605     $(".tabs .tabmenu li").click(function(){
606         var index = $(this).index();
607         $(this).addClass('curs').siblings().removeClass('curs');
608         $(this).parents(".tabs").find(".layout").hide();
609         $(this).parents(".tabs").find(".layout").eq(index).show();
610     });
611     
612     $(".returntop, .postop").click(function(){
613         $('html, body').stop().animate({scrollTop: $(".top").offset().top},200);
614     });
615     
616     $(".select").click(function(){
617         var curobj = this;
618         $(curobj).find(".selectchild").css("display", "block");
619         $(curobj).find(".selectvalue").click(function(){
620             $(this).addClass("selected").siblings().removeClass("selected");
621             $(curobj).find(".setselectvalue").val($(this).attr("data"));
622             $(curobj).find(".selecthtml").html($(this).html());
623             $(curobj).find(".selectchild").css("display", "none");
624             return false;
625         });
626     });
627     
628     $(".storelist .company").mouseenter(function(){
629         $(this).addClass("on").siblings().removeClass("on");
630     });
631     
632     $(".shadow").mouseenter(function(){
633         var obj = this;
634         $(obj).css("width", $(obj).attr("data-width")+"px").css("height", $(obj).attr("data-height")+"px");
635         $(obj).find("img").css("box-shadow", "0 0 10px 5px #"+$(obj).attr("data-color"));
636         $(obj).mouseleave(function(){
637             $(obj).find("img").css("box-shadow", "0 0 0");
638         });
639     });
640     
641     $(".shadow").each(function(){
642         var obj = this;
643         $(obj).css("width", $(obj).attr("data-width")+"px").css("height", $(obj).attr("data-height")+"px");
644     });
645     
646     $(".leftcart").click(function(){
647         var obj = this;
648         if($(obj).hasClass("extend")){
649             $(obj).removeClass("extend");
650             $(obj).parents(".leftnav").animate({width:'30px'}, "fast", function(){
651                 $(obj).parents(".leftnav").find(".carthtmlparent").css("width", "0px");
652             });
653         }else{
654             $(obj).parents(".leftnav").animate({width:'280px'}, "fast", function(){
655                 $(obj).parents(".leftnav").find(".carthtmlparent").css("width", "250px");
656             });
657             $(obj).addClass("extend");
658         }
659         
660     });
661     
662     $(document).on("click", '.closebt', function () {
663         var obj = this;
664         $(obj).parents(".leftnav").find(".leftcart").removeClass("extend");
665         $(obj).parents(".leftnav").animate({width:'30px'}, "fast", function(){
666             $(obj).parents(".leftnav").find(".carthtmlparent").css("width", "0px");
667         });
668     });
669     
670     $(document).on("click", '.clickajaxsend', function () {
671         var obj = this;
672         var beforefun = $(obj).attr("data-before")?$(obj).attr("data-before"):'';
673         var afterfun = $(obj).attr("data-after")?$(obj).attr("data-after"):'';
674         if(beforefun){
675             var result = eval(beforefun+"(obj);");
676             if(!result){
677                 return false;
678             }
679         }
680         if(!$(obj).attr("data-value")){
681             error($(obj).attr("data-error"));
682             return false;
683         }
684         if(!$(obj).attr("data-url")){
685             error("参数错误");
686             return false;
687         }
688         loadajax($(obj).attr("data-url"), $(obj).attr("data-value"), afterfun);
689     });
690     
691     $(document).on("click", '.radiobtn', function () {
692         $(this).parents(".radiolists").find(".icon-checkmark").removeClass("active");
693         $(this).find(".icon-checkmark").addClass("active");
694         $(this).parents(".radiolists").find(".radiovalue").val($(this).attr("data"));
695     });
696     
697     $(document).on("click", '.searcbt', function () {
698         if($("#setselectvalue").val()=="store"){
699             window.location = "/search.html?type=store&key="+encodeURI($("#searchkey").val());
700         }else{
701             window.location = "/search.html?key="+encodeURI($("#searchkey").val());
702         }
703     });
704 })
复制代码

 

posted @   Endv  阅读(668)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示