• 个人收藏实用代码


    1:获得IE版本
    <script  type="text/javascript">   


    var ua=navigator.userAgent.toLowerCase();
    var IEVer= /msie/.test(ua)?parseFloat(ua.match(/msie ([\d.]+)/)[1]):false;
    if(IEVer==6)
    {
     
    }

    </script> 
    2:GridView1设置主键
    GridView1.DataKeyNames = new string[] { "id"};//设置主键(这一句最好放在GridView1.DataBind();上面)
     string id = GridView1.DataKeys[e.RowIndex].Value.ToString();
    3:<a href="javascript:scroll(0,0)">返回顶部</a>
    4:[javascript]删除div的方法
    方法一:div.removeNode(true);//火狐不支持

    方法二:div.parentNode.removeChild(div);//IE火狐都支持
    5:vs 快捷键
    1:Ctrl+Shift+L: 删除当前行
    2:Ctrl+E,W: 自动换行
    3:Ctrl+G: 转到指定行
    6: this.lbtnDelALL.Attributes.Add("onclick", "return confirm('确定要删除吗?')");
    7:框架高度自适应<iframe id="iFrame1" name="iFrame1" width="100%" onload="this.height=iFrame1.document.body.scrollHeight" frameborder="0" src="index.htm"></iframe>
    8:$("button:eq(1)").click(function () {
        $("#panel").stop();//停止当前动画,继续下一个动画
       });
       $("button:eq(2)").click(function () {
        $("#panel").stop(true);//清除元素的所有动画
       });
       $("button:eq(3)").click(function () {
        $("#panel").stop(false,true);//让当前动画直接到达末状态 ,继续下一个动画
       });
       $("button:eq(4)").click(function () {
        $("#panel").stop(true,true);//清除元素的所有动画,让当前动画直接到达末状态
       });
    9:中文cookie
    设置  Response.Cookies["admin"]["flag"] = HttpUtility.UrlEncode(dt.Rows[0]["loginlimit"].ToString());
    读取 Encoding stre = Encoding.GetEncoding("UTF-8");
    string limit = HttpUtility.UrlDecode(Request.Cookies["user"]["flag"].ToString());

    10:打开新窗口 DropDownList1.Attributes.Add("onchange", "javascript:window.open(this.options[this.selectedIndex].value)");
    11:3:this.ddlPage.Items.Add(new ListItem("=请选择=", "0"));
     this.ddlPage.Items.Add(new ListItem("第" + i.ToString() + "页", i.ToString()));
    12:1:Response.AddHeader("Refresh", "10"); 写在pageload中 
    <meta http-equiv="Refresh" content="10" />  写在<head></head>中
    <%Response.AddHeader("Refresh", "10"); %>  写在body中

    13:隔行变色 $(".color").find("tr").each(function(i){this.style.backgroundColor=['#ffffff','#eee'][i%2]})

    14:弹出窗口:

    <script type="text/javascript" language="javascript">

                function sAlert(){
                var fa=document.getElementById("fa");
                fa.innerHTML="法律声明";
                var msgw,msgh,bordercolor;
                msgw=788;//提示窗口的宽度
                msgh=328;//提示窗口的高度
                titleheight=15 //提示窗口标题高度
                bordercolor="#ffffff";//提示窗口的边框颜色
                titlecolor="#ffffff";//提示窗口的标题颜色
               
                var sWidth,sHeight;
                sWidth=document.body.offsetWidth;
                sHeight=document.body.scrollHeight+30;//screen.height;

                var bgObj=document.createElement("div");
                bgObj.setAttribute('id','bgDiv');
                bgObj.style.position="absolute";
                bgObj.style.top="0";
                bgObj.style.background="#777";
                bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity=40)";
               
                bgObj.style.left="0";
                bgObj.style.width=sWidth + "px";
                bgObj.style.height=sHeight + "px";
                bgObj.style.zIndex = "10000";
                document.body.appendChild(bgObj);
               
                var msgObj=document.createElement("div")
                msgObj.setAttribute("id","msgDiv");
                msgObj.setAttribute("align","center");
                msgObj.style.background="white";
                msgObj.style.border="1px solid " + bordercolor;
                msgObj.style.position = "absolute";
                msgObj.style.left = "36%";
                msgObj.style.top = "30%";
                msgObj.style.font="12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif";
                msgObj.style.marginLeft = "-225px" ;
                msgObj.style.marginTop = -75+document.documentElement.scrollTop+"px";
                msgObj.style.width = msgw + "px";
                msgObj.style.height =msgh + "px";
                msgObj.style.textAlign = "center";
                msgObj.style.lineHeight ="25px";
                msgObj.style.zIndex = "10001";
      
               var title=document.createElement("h4");
               title.setAttribute("id","msgTitle");
               title.setAttribute("align","right");
               title.style.margin="0";
               title.style.padding="0px";
               title.style.background=bordercolor;
               title.style.filter="progid:DXImageTransform.Microsoft.Alpha(startX=20, startY=20, finishX=100, finishY=100,style=1,opacity=75,finishOpacity=100);";
               title.style.opacity="0.75";
           
               title.style.height="15px";
                 title.style.width="788px";
               title.style.font="12px Verdana, Geneva, Arial, Helvetica, sans-serif";
               title.style.color="white";
               title.style.cursor="pointer";
               title.innerHTML="<img src=\"images/closelabel.gif\" style=\"margin-top:4px\">";
               title.onclick=function(){
                    document.body.removeChild(bgObj);
                       var fa=document.getElementById("fa");
                fa.innerHTML="<a onclick=\"sAlert();\">法律声明</a>";
                    document.getElementById("msgDiv").removeChild(title);
                    document.body.removeChild(msgObj);
                    }
               document.body.appendChild(msgObj);
               document.getElementById("msgDiv").appendChild(title);
               var txt=document.createElement("p");
               txt.style.margin="0"
               txt.setAttribute("id","msgTxt");
               txt.innerHTML="<img src=\"images/fl.jpg\">";
               document.getElementById("msgDiv").appendChild(txt);
                }
            </script>

    15:删除数据库中重复记录:

    delete from DotBBS_t130dft_User
    where userid  in (select  userid  from DotBBS_t130dft_User  group  by  userid   having  count(userid) > 1)
    and uid not in (select min(uid) from  DotBBS_t130dft_User  group by userid  having count(userid )>1)
    16:标题跑马灯
      <script type="text/javascript">
          function  set() {
              var tit = document.title;
              var a = tit.substring(0, 1);
              var b = tit.substring(1, tit.length);
              document.title = b + a;
          }
          setInterval(set,500);
      </script>

    17:删除文本编辑器上传的图片

     private string GetImgString(string str)
        {
            string res = "";
            string tem = "";
            int startIndex = 0;
            int endIndex = 0;
            for (int i = 0; i < str.Length - 3; i++)
            {
                tem = str.Substring(i, 3).ToLower();
                if (tem == "src")
                {
                    startIndex = i;
                    str = str.Substring(startIndex+5);
                    endIndex = str.IndexOf('>');
                    res = str.Substring(0, endIndex-3);
                    str = str.Substring(endIndex);
                    res += "|"+GetImgString(str); //递归调用               
                    break;
                }
            }
            return res;
        }
        protected void dgrdName_ItemCommand(object source, DataGridCommandEventArgs e)
        {
           
            if (e.CommandName == "Delete")
            {
                int id = Convert.ToInt32(e.CommandArgument.ToString());

                string str = "select [content] from news where id="+id+"";
                string content = haian.ReadOut2(str);
                string img=GetImgString(content);
                img = img.Substring(0,img.Length-1);
                string [] arr=img.Split('|');
                for (int i = 0; i < arr.Length;i++ )
                {
                  
                
                 
                    File.Delete(HttpContext.Current.Server.MapPath("/" + arr[i]));
                 
                }
             
               string delstr = "delete  from news where id=" + id + "";
                haian.myCommand(delstr);
                DataBind();

            }
           
        }

    17:取出文本编辑器里上传的所有图片
    private string GetImgString(string str)
        {
            string res = "";
            string tem = "";
            int startIndex = 0;
            int endIndex = 0;
            for (int i = 0; i < str.Length; i++)
            {
                tem = str.Substring(i, 4).ToLower();
                if (tem == "<img")
                {
                    startIndex = i;
                    str = str.Substring(startIndex);
                    endIndex = str.IndexOf('>');
                    res = str.Substring(0, endIndex + 1);
                    break;
                }
            }
            return res;
        }

    18:去掉IE浏览器里的脚本控件提示
    <!-- saved from url=(0014)about:internet -->

    19:去除超链接边框
    a{blr:expression(this.onFocus=this.blur())}

    20:去除IE下flash边框
    <script src="javascript:'document.body.innerHTML+=\'\'';"></script>

    21:判断浏览器类型
    <script type="text/javascript">
            var Sys = {};
            var ua = navigator.userAgent.toLowerCase();
            var s;
            (s = ua.match(/msie ([\d.]+)/)) ? Sys.ie = s[1] :
            (s = ua.match(/firefox\/([\d.]+)/)) ? Sys.firefox = s[1] :
            (s = ua.match(/chrome\/([\d.]+)/)) ? Sys.chrome = s[1] :
            (s = ua.match(/opera.([\d.]+)/)) ? Sys.opera = s[1] :
            (s = ua.match(/version\/([\d.]+).*safari/)) ? Sys.safari = s[1] : 0;

            //以下进行测试
            var colin=document.getElementById("colin");
            if(Sys.ie=="8.0")
            {
            colin.style.marginTop="0px";
            }
            if (Sys.ie) document.write('IE: ' + Sys.ie);
            if (Sys.firefox) document.write('Firefox: ' + Sys.firefox);
            if (Sys.chrome) document.write('Chrome: ' + Sys.chrome);
            if (Sys.opera) document.write('Opera: ' + Sys.opera);
            if (Sys.safari) document.write('Safari: ' + Sys.safari);
        </script>
    22:防下载

    <div style="display:none;">
    <script language="javascript">
    window.setInterval("clipboardData.setData('text','')",100);
    </script>
    <noscript><iframe src=*.html></iframe></noscript>
    </div>

    23:初始化滚动条
    <script>
    function scrollWindow()
     {
      window.scrollTo(0,150)
     }
    scrollWindow();
    </script>
    <body bgcolor="#000000" style="margin:0;"  onload="scrollWindow();" scroll="no">

    flash 部分

     1:鼠标悬停加颜色
    var s:ColorTransform = new ColorTransform();
              s.color = 0x000000;
              e.currentTarget.transform.colorTransform = s;
    2:鼠标悬停设置透明度
    e.target.alpha=0.8;
    3:页面跳转
    navigateToURL(new URLRequest("news.aspx"),"_self");
    中文转码跳转
     navigateToURL(new URLRequest("floor.aspx?city="+encodeURI(arr[i])),"_self");
    4:动态读取xml文件
    var newsXml:XML=new XML();
     var xmlLoader:URLLoader=new URLLoader();
     xmlLoader.load(new URLRequest("Common/news.ashx"));
     xmlLoader.addEventListener(Event.COMPLETE,loadNewsXml); 
     function loadNewsXml(evt:Event){
      newsXml=XML(evt.target.data);
      //trace(newsXml.news)
      viewNewsList(newsXml.news);
     }

  • 相关阅读:
    JZOJ 3034. 【NOIP2012模拟10.17】独立集
    JZOJ 3035. 【NOIP2012模拟10.17】铁轨
    JZOJ 1259. 牛棚安排
    数位DP JZOJ 3316. 非回文数字
    JZOJ 3046. 游戏
    JZOJ 3013. 填充棋盘
    debian 安装oracle提供的java8
    java 汉字转拼音 PinYin4j
    debian ssh设置root权限登陆 Permission denied, please try again
    java并发下订单生成策略
  • 原文地址:https://www.cnblogs.com/zhang9418hn/p/1982160.html
Copyright © 2020-2023  润新知