Net后台+ html + Jquery不得不写的一些小功能和格式

1.导航用的样式标齐
var curl = document.location.href;
    $("#menu li").removeClass('active');
    if (curl.indexOf('/news') >= 0) {
        $('.news').addClass('active');
    } else if (curl.indexOf('/Taldent1') >= 0) {
        $('.Taldent1').addClass('active');
    } else {
        $('.index1').addClass('active');
    }
$("ul li a").each(function() {
  if (location.href.indexOf($(this).attr("href")) >= 0) {
   $(this).addClass("active"); 
   }
});
2.圆角样式
border: 1px solid #dedede;
    -moz-border-radius: 10px;      /* Gecko browsers */
    -webkit-border-radius: 10px;   /* Webkit browsers */
    border-radius:10px;  
3.Jquery简单身份证检查方法
function cidInfo(sId) {
        var iSum = 0;
        var info = "";
        var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
        var aCity = { 11: "北京", 12: "天津", 13: "河北", 14: "山西", 15: "内蒙古", 21: "辽宁", 22: "吉林", 23: "黑龙江 ", 31: "上海", 32: "江苏", 33: "浙江", 34: "安徽", 35: "福建", 36: "江西", 37: "山东", 41: "河南", 42: "湖北 ", 43: "湖南", 44: "广东", 45: "广西", 46: "海南", 50: "重庆", 51: "四川", 52: "贵州", 53: "云南", 54: "西藏 ", 61: "陕西", 62: "甘肃", 63: "青海", 64: "宁夏", 65: "新疆", 71: "台湾", 81: "香港", 82: "澳门", 91: "国外 " }
        if (!reg.test(sId)) return "Error:非法身份证号";
        sId = sId.replace(/x$/i, "a");
        if (aCity[parseInt(sId.substr(0, 2))] == null) return "Error:非法地区";
        sBirthday = sId.substr(6, 4) + "-" + Number(sId.substr(10, 2)) + "-" + Number(sId.substr(12, 2));
        var d = new Date(sBirthday.replace(/-/g, "/"));
        if (sBirthday != (d.getFullYear() + "-" + (d.getMonth() + 1) + "-" + d.getDate())) return "Error:非法生日";
        for (var i = 17; i >= 0; i--) iSum += (Math.pow(2, i) % 11) * parseInt(sId.charAt(17 - i), 11);
        if (iSum % 11 != 1) return "Error:非法证号";
        return true;
        //return aCity[parseInt(sId.substr(0, 2))] + "," + sBirthday + "," + (sId.substr(16, 1) % 2 ? "男" : "女");
    }

NET后台身份证GB11643-1999标准验证

public bool Validate_Card(string idNumber)
        {
            if (idNumber.Length == 18)
            {
                #region 18位身份证
                long n = 0;
                /*若转换成功与失败,为真n返回为数字,假为0
                 * 前面17位可能为x,so 防范
                */
                if (long.TryParse(idNumber.Remove(17), out n) == false || n < Math.Pow(10, 16) || long.TryParse(idNumber.Replace('x', '0').Replace('X', '0'), out n) == false)
                {
                    return false;//数字验证 
                }
                string address = "11x22x35x44x53x12x23x36x45x54x13x31x37x46x61x14x32x41x50x62x15x33x42x51x63x21x34x43x52x64x65x71x81x82x91";
                if (address.IndexOf(idNumber.Remove(2)) == -1)//保留前2位省份
                {
                    return false;//省份验证失败 
                }
                string birth = idNumber.Substring(6, 8).Insert(6, "-").Insert(4, "-");
                DateTime time = new DateTime();
                if (DateTime.TryParse(birth, out time) == false)
                {
                    return false;//生日验证失败 
                }
                /*身份证第18位(校验码)的计算方法 
                */
                string[] arrVarifyCode = ("1,0,x,9,8,7,6,5,4,3,2").Split(',');
                string[] Wi = ("7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2").Split(',');
                char[] Ai = idNumber.Remove(17).ToCharArray();//转化字符数组
                int sum = 0;
                for (int i = 0; i < 17; i++)
                {
                    sum += int.Parse(Wi[i]) * int.Parse(Ai[i].ToString());//总数和
                }
                int y = -1;
                //y作为下表分别对应arrVarifyCode数组中值,身份证最后一位必须和arrVarifyCode[y]相等
                Math.DivRem(sum, 11, out y);
                if (arrVarifyCode[y] != idNumber.Substring(17, 1).ToLower())
                {
                    return false;//校验码验证失败 
                }
                return true;//符合GB11643-1999标准
                #endregion
            }
            else if (idNumber.Length == 15)
            {
                #region 15位身份证
                long n = 0;
                if (long.TryParse(idNumber, out n) == false || n < Math.Pow(10, 14))
                {
                    return false;//数字验证 
                }
                string address = "11x22x35x44x53x12x23x36x45x54x13x31x37x46x61x14x32x41x50x62x15x33x42x51x63x21x34x43x52x64x65x71x81x82x91";
                if (address.IndexOf(idNumber.Remove(2)) == -1)
                {
                    return false;//省份验证 
                }
                string birth = idNumber.Substring(6, 6).Insert(4, "-").Insert(2, "-");
                DateTime time = new DateTime();
                if (DateTime.TryParse(birth, out time) == false)
                {
                    return false;//生日验证 
                }
                return true;//符合15位身份证标准
                #endregion
            }
            else
            {
                return false;
            }
        }


4.密码级别小检验

//检查密码安全级别
    function AnalyzePasswordSecurityLevel(password) {
        var securityLevelFlag = 0;
        if (password.length < 6) {
            return 0;
        }
        else {
            if (/[a-z]/.test(password)) {
                securityLevelFlag++;    //lowercase
            }
            if (/[A-Z]/.test(password)) {
                securityLevelFlag++;    //uppercase
            }
            if (/[0-9]/.test(password)) {
                securityLevelFlag++;    //digital
            }
            if (containSpecialChar(password)) {
                securityLevelFlag++;    //specialcase
            }
            return securityLevelFlag;
        }
    }

    function containSpecialChar(str) {
        var containSpecial = RegExp(/[(\ )(\~)(\!)(\)(\#)(\$)(\%)(\^)(\&)(\*)(\()(\))(\-)(\_)(\+)(\=)(\[)(\])(\{)(\})(\|)(\\)(\;)(\:)(\')(\")(\,)(\.)(\/)(\<)(\>)(\?)(\)]+/);
    return (containSpecial.test(str));
    }

4.背景格式

$(".position .tabs .hot a").css({ "background": "url(/images/images/label_03.png) no-repeat right 0" });
background:url(/images/images/icon_user.png) no-repeat 0 9px;

5.setTimeout的循环执行

window.setTimeout("interval();", 60000);//1000代表1秒

function interval() {
        $.ajax({
            url: "/Home/LearnTimeAdd",
            data: {},
            success: function (data) {
            },
            error: function (data) {
                //alert(data)
            }
        })
        window.setTimeout("interval();", 60000);
    }

6.在页面中我常常使用@Html.Raw(a.Content) 来显示富文本编辑器中内容,但是有时,我们又不得不只需要文字,这是我们就需要去除标签
       string strText = System.Text.RegularExpressions.Regex.Replace(a.Content, "<[^>]+>", "");
       strText = System.Text.RegularExpressions.Regex.Replace(strText, "&[^;]+;", "");
       string content = strText.Length > 40 ? strText.Substring(0, 40) : strText.Substring(0, strText.Length - 2);
      //当然如果不是正确的<img src="" />,完整的标签是去除不了的           


7.富文本编辑器  Ueditor 1.4.3.1 NET版本

格式我就不说了,官网上都是有的  ,最开始的时候我们出现需要去寻找Net.Json,看bin目录下有没有,没有的话,加载后需要引入

若出现
请求后台配置项http异常,上传功能将不能正常使用
谷歌浏览器 报错

Config类报错:

Error reading JObject from JsonReader. Current JsonReader item is not an object: Comment. Path '', line 1, position 28.
赶快找到config.json文件 把第一行注释删除!    具体有的可以,有的不可以,我的理解是编码的问题,若有其他的信息,NET Ueditor可以留言


下面就是配置图片的路径前缀 Config.json

 配置为: "imageUrlPrefix": "/scripts/ueditor/", /* 图片访问路径前缀 */ 

这个就自己根据浏览器,路径对不对 自己修改了,简单

<pre name="code" class="plain">另外http://blog.csdn.net/unopenmycode/article/details/37598597还有详解
 
 

8.时间差的计算让我们用到TimeSpan

TimeSpan ts = item.StartDate - now;
TimeSpan endsd = item.EndDate - now;
int sd = ts.Days;
TimeSpan 有一些属性:Days、TotalDays、Hours、TotalHours、Minutes、TotalMinutes、Seconds、TotalSeconds、Ticks,我们根据需要得到想要的秒,分,小时...


9.时间格式的验证TryParse

 DateTime dtDate = Convert.ToDateTime("1999-09-09");
 //转换失败dtDate等于原来值,转换成功返回成功的值,但是需要注意 默认null为0001/01/01格式也是对的哦!
 if (DateTime.TryParse(_ditime, out dtDate))
{
    _model.dfiTime = dtDate;
}
 else { _model.dfiTime = dtDate; }

10.SubString,Replace,Remove,添加,取最大,LastIndexOf,IndexOf   更多可以参考点击打开链接

字符串的截取:SubString(指定的开始位置,指定的个数)

子字串的替换:Replace(“子串中连续的”,“想要替换为的”)

删除:Remove  (从指定位置开始,删除的字符个数)


11.我们经常在cshtml页面中运算,格式@(_model.Name.Length>10? _model.Name.Substring(0,10):_model.Name),用@(    )


12我们常常挑错用System.Data.Entity.Validation.DbEntityValidationException

                  catch (System.Data.Entity.Validation.DbEntityValidationException ex)
                  {
                        ErrorCoun++;
                        string error = "";
                        foreach (var item in ex.EntityValidationErrors)
                        {
                            foreach (var i_ in item.ValidationErrors)
                            {
                                error += i_.PropertyName + "|" + i_.ErrorMessage + "-------";
                            }
                        }
                    }




 



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值