前端开发中快速掌握的技巧
发布时间:2021-02-19 06:15:10 所属栏目:大数据 来源:网络整理
导读:之前开发过程中没有太在意前端方法的封装,最近在项目里看到别人封装的方法了,实在太有用了,自己总结了一下,好东西就应该共享一下 表单验证非空: 以前我都是将需要验证的字段在js中拿到这个字段的变量,然后判断这个变量是否是空值的,相信你也是这样的
- 3加载jsp中的空间 /** * 加载 下拉框 * @param jsonArray */ function loadSelectData(jsonArray,select) { $("select[column='"+select+"']").empty(); $.each(jsonArray,function(i) { // 遍历下拉框数据 var data = jsonArray[i]; $("select[column='"+select+"']").append('<option value="'+data.ID+'">'+data.NAME+'</option>'); }); }
// 写cookie function _setCookie(key,value,time) { var strsec = getsec(time); var exp = new Date(); exp.setTime(exp.getTime() + strsec * 1); document.cookie = key + "=" + escape(value) + ";expires=" + exp.toGMTString(); }
// 获取cookie时间 function getsec(str) { var str1 = str.substring(1,str.length) * 1; var str2 = str.substring(0,1); if (str2 == "s") { return str1 * 1000; } else if (str2 == "h") { return str1 * 60 * 60 * 1000; } else if (str2 == "d") { return str1 * 24 * 60 * 60 * 1000; } }
// 获取cookie function _getCookie(key) { var arr,reg = new RegExp("(^| )" + key + "=([^;]*)(;|$)"); if (arr = document.cookie.match(reg)) return unescape(arr[2]); else return null; }
// 删除cookie function _delCookie(key) { var exp = new Date(); exp.setTime(exp.getTime() - 1); var cval = _getCookie(key); if (cval != null) document.cookie = key + "=" + cval + ";expires=" + exp.toGMTString(); }
$(document).ready(function() { if (navigator.userAgent.match(/msie/i) ){ alert('I am an old fashioned Internet Explorer'); } });
$(function(){ var $win = $(window) var $nav = $('.mytoolbar'); var navTop = $('.mytoolbar').length && $('.mytoolbar').offset().top; var isFixed=0; processScroll() $win.on('scroll',processScroll) function processScroll() { var i,scrollTop = $win.scrollTop() if (scrollTop >= navTop && !isFixed) { isFixed = 1 $nav.addClass('subnav-fixed') } else if (scrollTop <= navTop && isFixed) { isFixed = 0 $nav.removeClass('subnav-fixed') } }
`$('li').replaceWith(function(){ return $(" ").append($(this).contents()); });`
$("#textA").bind('copy',function() { $('span').text('copy behaviour detected!') }); $("#textA").bind('paste',function() { $('span').text('paste behaviour detected!') }); $("#textA").bind('cut',function() { $('span').text('cut behaviour detected!') });
var root = location.protocol + '//' + location.host; $('a').not(':contains(root)').click(function(){ this.target = "_blank"; });
$('input.nospace').keydown(function(e) { if (e.keyCode == 32) { return false; } });
(编辑:滨州站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |