随笔2

google登录地址:老D博客

.net设计模式

http://caniuse.com/

http://www.iconfont.cn/  图标

http://network.51cto.com/art/201508/488400.htm

ColorPix

 

chrome bookmark目录:C:\Users\admin\AppData\Local\Google\Chrome\User Data\Default\bookmark

 

 

\\10.100.5.107\d$\      共享目录访问方式

 

jquery的一种实现:

var obj = [];

var trObj = objRoot.find('tr.selected');

obj.push({id: trObj.attr('productId'), name: trObj.attr('productName')});

另一种更好的方式:

var obj = [];

objRoot.find('tr.selected').each(function (){

  obj.push({id: $(this).attr('productId'), name: $(this).attr('productName')});

})

 

jQuery回调方法通过返回false来取消默认的行为并阻止事件起泡。

jQuery 代码:

$("form").bind("submit", function() { return false; }) //阻止提交

通过使用 preventDefault() 方法只取消默认的行为。

jQuery 代码:

$("form").bind("submit", function(event){
  event.preventDefault();
});

 

USE [WindWMNew1_DB]
GO
/****** Object:  StoredProcedure [dbo].[Sp_Home_UserProduct_Update_SortField]    Script Date: 07/20/2015 15:35:41 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:        hzhang.Ashe
-- Create date: 2014.11.05
-- Description:    用户产品表更新排序字段
-- =============================================
ALTER PROCEDURE [dbo].[Sp_Home_UserProduct_Update_SortField]
    -- Add the parameters for the stored procedure here
    @sortField int,
    @ids varchar(500)
AS
BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;
declare @id varchar(10),@sql varchar(200)

    -- Insert statements for procedure here
--分隔以“,”隔开的id字符串
while charindex(',',@ids) > 0
begin
--获取单个字符串
set @id=LEFT(@ids,charindex(',',@ids)-1)
--删除读取过的Id
set @ids=stuff(@ids,1,charindex(',',@ids),'')
--更新表中的排序号
update Tb_Home_UserProductRelation set SortField=@sortField where id=cast(@id as int)
--设置下一个排序号
set @sortField=@sortField+1
end
--判断字符串是否存在未更新的id
if len(@ids)>0
begin 
update Tb_Home_UserProductRelation set SortField=@sortField where id=cast(@ids as int)
end
END
View Code
USE [WindWMNew1_DB]
GO
/****** Object:  StoredProcedure [dbo].[Sp_Home_UserProduct_Add]    Script Date: 07/20/2015 09:48:38 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: whqiu
-- Create date: 2013-03-21
-- Description: Add a product or a windcode
--   in Table dbo.Tb_Home_UserProductRelation
-- Example: 
--   Sp_Home_UserProduct_Add 'w0807053',Null,'600000.SH',1,'2013-03-15',0
--   Sp_Home_UserProduct_Add 'w0807053',1, Null,1,'2013-03-15',0
-- Check: select * from Tb_Home_UserProductRelation
-- =============================================
ALTER procedure [dbo].[Sp_Home_UserProduct_Add](
  @userId varchar(50),--此用户id
  @productId varchar(max),
  @windcode varchar(max),
  @shareUserId varchar(max),--接受共享的用户IDList
  @shareFromUserName varchar(100)--此用户的IM名
)
as
begin    
    --共享的产品
    if @shareUserId<>''
        begin
            DECLARE @temptb TABLE  
            (  
                [id] int identity(1,1),  
                UserID varchar(50)
            )
            Declare @currentIndex int  
            Declare @totalRows    int
            Declare @oneShareUserId  varchar(50)  
            Declare @sort int
            insert into @temptb(UserID) select s from dbo.fn_SplitString(@shareUserId, ',')
            select @currentIndex=1  
            select @totalRows=count(1) from @temptb
                
            while(@currentIndex<=@totalRows)  
            begin  
                  select @oneShareUserId=null  
                  select @oneShareUserId=UserID from @temptb where id=@currentIndex
                  if @oneShareUserId <>''
                    begin
                        --取出当前排序最大号
                        SELECT @sort= case max(sortfield) when null then 1 else max(sortfield)  end 
                        FROM [WFC_DB].[dbo].[Tb_Home_UserProductRelation]
                        where (userid=@oneShareUserId or shareuserid=@oneShareUserId) and status=0 and sortfield is not null
                        IF EXISTS (SELECT ShareUserId FROM Tb_Home_UserProductRelation WHERE ShareUserId =@oneShareUserId  and UserId=@userId and ProductId=@productId and WindCode=@windcode)
                            update Tb_Home_UserProductRelation set [Status]=0,SortField=@sort 
                            WHERE ShareUserId =@oneShareUserId  
                                  and UserId=@userId 
                                  and ProductId=@productId 
                                  and WindCode=@windcode
                else
                            insert into Tb_Home_UserProductRelation 
                                      (
                                          ShareUserId,
                                          ShareFromUserName,
                                          UserId,ProductId,
                                          WindCode,Priority,
                                          [Status],
                                          IsSelected,
                                          SortField
                                      )
                                values(
                                          @oneShareUserId,
                                          @shareFromUserName,
                                          @userId,
                                          @productId,
                                          @windcode,
                                          2,
                                          0,
                                          0,
                                          @sort
                                )  
                            select @currentIndex=@currentIndex+1; 
                    end 
            end  
            
            update Tb_Home_UserProductRelation
            set ShareFromUserName = '已共享',
                UpdateDate = getdate()
            where UserId = @UserId 
                    and (ShareFromUserName='' or ShareFromUserName is null)
                    and (windcode = @windcode or ProductId=@productId)
                    and Status = 0 
        end
    else
        begin
            -- @productId 会存在多值(,分割的字符串)
              if @productId <> ''
              begin
                update dbo.Tb_Home_UserProductRelation
                set [Status] = 0,
                  IsSelected = 1,
                  UpdateDate = getdate(),
                  SortField=(
                    select  
                    case max(sortfield) 
                    when null  then 1 
                    else  max(sortfield)+1 end as sortField
                    from Tb_Home_UserProductRelation  
                    where (userid=@userId or shareuserid=@userId) and status=0 and sortfield is not null )
                where UserId = @userId
                  and WindCode is null
                  and exists 
                  (
                    select s 
                    from dbo.fn_SplitString(@productId, ',')
                    where s = ProductId
                  ) 
                insert into dbo.Tb_Home_UserProductRelation
                  (UserId,ProductId,WindCode,Priority,Status,IsSelected,SortField)
                select @userId, a.s, null, 1, cast(0 as smallint), 1,b.sortField
                from dbo.fn_SplitString(@productId, ',') as a,  
                (
                    select  
                    case max(sortfield) 
                    when null  then 1 
                    else  max(sortfield)+1 end as sortField
                    from Tb_Home_UserProductRelation  
                    where (userid=@userId or shareuserid=@userId) and status=0 and sortfield is not null ) as b
                where not exists
                (
                  select ProductId 
                  from Tb_Home_UserProductRelation r
                  where r.ProductId = a.s
                    and r.userid= @userId
                )
              end
              -- @windcode 会存在多值(,分割的字符串)
              if @windcode <> ''
              begin
                update dbo.Tb_Home_UserProductRelation
                set [Status] = 0,
                  IsSelected = 1,
                  UpdateDate = getdate(),
                  SortField=(
                    select  
                    case max(sortfield) 
                    when null  then 1 
                    else  max(sortfield)+1 end as sortField
                    from Tb_Home_UserProductRelation  
                    where (userid=@userId or shareuserid=@userId) and status=0 and sortfield is not null )
                where UserId = @userId
                  and ProductId is null
                  and exists 
                  (
                    select s 
                    from dbo.fn_SplitString(@windcode, ',')
                    where s = WindCode
                  )
                
                insert into dbo.Tb_Home_UserProductRelation
                  (UserId,ProductId,WindCode,Priority,Status,IsSelected,sortField)
                select @userId, null, a.s, 1, cast(0 as smallint), 1,b.sortField
                from dbo.fn_SplitString(@windcode, ',') as a,
                (
                    select  
                    case max(sortfield) 
                    when null  then 1 
                    else  max(sortfield)+1 end as sortField
                    from Tb_Home_UserProductRelation  
                    where (userid=@userId or shareuserid=@userId) and status=0 and sortfield is not null ) as b
                where not exists
                (
                  select windcode 
                  from Tb_Home_UserProductRelation r
                  where r.windcode = a.s
                    and r.userid= @userId
                )
              end
        end
end
View Code

 

jquery disable用法

$('#mySpace').attr("disabled", false)

 

<script>标签如果放在html之后,浏览器解析时会解析为放置在<body>标签的末尾

js的动态加载以及响应事件

                var $;
                $ = document.createElement("script");
                $.src = this.ServiceBase + this.version + "/" + _ + ".js";
                $.type = "text/javascript";
                $.language = "javascript";
                document.getElementsByTagName("head")[0].appendChild($);
                $.onload = $.onreadystatechange = function () {
                    if (this.readyState && (this.readyState != 'complete' && this.readyState != "loaded"))
                        return;
                    else {
                        __self.curr++;
                        if (__self.curr == __self.count)
                            __self.OnLoaded()
                    }
                }
View Code

 

apsx页面的响应特点:

    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Write("00000"); // html输出流的前面,即<html>之前
        }

        protected override void Render(HtmlTextWriter writer)
        {
            base.Render(writer); // 若注释该段代码,则无apsx页面的输出,只有Response.Write的输出
            Response.Write("test"); // html输出流的后面,即</html>之后
        }
    }
View Code

在chrome中network下查看实际从服务器返回的字符串

 

关于css浮动(float)的说明:

1、当浮动元素位于行内元素中时,将形成环绕效果,详见w3school实例

2、当浮动元素位于块级元素中时

  1、与浮动元素同级的无块级元素,这时父元素不能被子元素撑开,浮动元素表现为脱离文档流

  2、与浮动元素同级的有块级元素

    1、块级元素位于浮动元素之前,浮动元素在浮动时会以块级元素边框为界,并不会覆盖该块级元素,浮动元素表现为文档流

    2、块级元素位于浮动元素之后,浮动元素会覆盖块级元素,浮动元素表现为脱离文档流

    该现象的解释可参见“CSS权威指南”书中关于浮动行为准则的第4条,即若浮动元素为块级元素,则浮动元素表现为在一个父级块元素中

3、以上均为浮动的实际表现,实际上浮动脱离文档流,父元素均不会被子浮动元素撑开,这种情况下需要清理,清理有两种方式:

    1、在每个元素的最后添加<div style="clear:both;"></div>, 从而分别清理

    2、设需要清理的元素也为浮动,对最外层需要清理的元素统一清理

4、对于清理,可以为父元素样式设为overflow:hidden,同样能达到清理的效果(比较诡异)

以上为在ie11和chrome测试情况,测试代码可参考:

    <div>
        <div style="height:50px; background-color:Blue;"></div>
        <div style="width:100%; float:left;" >
            <div style="float:left; width:40%; height:50px; border:1px solid gray; background-color:White;"></div>
            <div style="float:left; width:50%; height:50px; border:1px solid red"></div>
            <div style="height:50px; border:1px solid gray; background-color:green;"></div>
        </div>
    </div>
View Code

 

html元素的属性可分为三类:

1、html预定义属性,如style等

  该类型可以在js中以js对象属性的方式操纵,操纵的结果会展示在html文档中

2、html用户自定义属性

  该类型只能在js中使用方法setAttribute或getAttribute操纵,操纵的结果会展示在html文档中,自定义属性不能赋予js对象(赋为对象时,html文档中展示位[object object],对象丢失)

3、js对象属性

  该类型将html元素作为js对象(DOM对象)进而添加新属性,操纵的结果不会展示在html文档中,该类型可以赋值js对象

jQuery中$().attr()对应1和2,$().prop()对应3

 

aspx页面Response.Write的使用:

后台代码:

    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string name = System.Configuration.ConfigurationManager.AppSettings["Name"];
            Response.Write(name); // html输出流的前面,即<html>之前
        }

        protected override void Render(HtmlTextWriter writer)
        {
            base.Render(writer); // 若注释该段代码,则无apsx页面的输出,只有Response.Write的输出
            Response.Write("test"); // html输出流的后面,即</html>之后
        }
    }
View Code

 

HighChart使用注意事项:

1、设置某一条线的可见与否,即lengend是否选中,方法如下:

  series:[{

    name: 'shanghai',

    visible: false,

    data:[1, 1, 3, 9]

  }]

 

在站点下获取物理路径的方法:

1、HttpServerUtility.MapPath(),一般在继承至IHttpHandler的类中使用,访问方式为HttpContext.Server

  server.MapPath("/"); // 映射应用程序根目录,如“D:\\svn\\WebTest\\”

  server.MapPath("/aa"); // 映射指定的文件或文件夹,不检查该文件或文件夹是否存在,如“D:\\svn\\WebTest\\aa”

2、AppDomain.CurrentDomain.BaseDirectory, 与server.MapPath("/")相同

 

ajax调试的一个技巧:使用chrome的http请求与相应包查看与服务器交互状态,而非ajax的onerror相应事件

 

iis会检测站点下的文件变动,并判断是否重启应用程序池

1、当web.config、Global.asax、bin目录下的任何文件发生变动时,iis自动重启应用程序池

2、.aspx、.js、.css、.xml等其他文件变动,iis不会重启应用程序池

3、默认情况下,浏览器(ie、chrome)在浏览页面时,.aspx、.js、.css文件的更改会及时更新的页面响应中,因此,在调试阶段修改这些文件并在浏览器查看效果时,只需刷新页面,无需清理缓存

 

分别使用http与https请求页面时,加载页面其他资源(如js等)的几个注意事项(ie7、ie8、ie11、chrome均一致):

当该资源域名与当前页面相同时

1、使用https的方式不能通过http加载该资源,浏览器会阻止该请求

2、使用http的方式可以通过https加载该资源

3、使用https的方式可以通过https加载该资源

当该资源域名与当前页面不同时

1、使用https的方式不能通过http加载该资源,浏览器会阻止该请求

2、使用http的方式不能通过https加载该资源,请求失败

3、使用https的方式不能通过https加载该资源,请求失败

 

添加单击事件,实现页面某一区域滚动可见的两种方式:

1、<a>标签的锚

2、在目标元素上调用scrollIntoView()方法

这两种方式在ie7+、chrome均支持,其中第一中方法简单,但第二种方法更灵活一些

 

HttpResponse输出流的两种方式:

1、输出字符串:HttpResponse.Write()

2、输出流:HttpResponse.BinaryWrite()或HttpResponse.OutputStream.Write()

注意:在输出流时*(如图片等),需指明ContentType,必要时在写入字节流前可能需要调用HttpResponse.Clear()清理输出

 

在后台通过http或https访问页面的方法:

using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Net.Security;
using System.Text;

namespace Wind.Data
{
    /// <summary>
    /// 请求其他站点Web应用程序数据接口类
    /// </summary>
    public class WebAPIData
    {
        /// <summary>
        /// 从F11获取基金总评
        /// </summary>
        /// <param name="windcode">windcode列表(以逗号分隔)</param>
        /// <param name="pageType">windcode对应总评类型(以逗号分隔)</param>
        /// <returns>总评</returns>
        public string GetF11GeneralComment(string parameters)
        {
            string url = Common.Utils.GetSectionConfigValue("Wind.WealthManagement/WFC", "FundWebAddress");

            return GetHttpResponse(url + "WordHandler.ashx?windcodepagetype=" + parameters + "&menuId=999");
        }

        /// <summary>
        /// 获取http或https请求
        /// </summary>
        /// <param name="url">url</param>
        /// <returns>响应数据</returns>
        private string GetHttpResponse(string url)
        {
            return GetHttpResponse(url, null);
        }

        /// <summary>
        /// 获取http或https请求
        /// </summary>
        /// <param name="url">url</param>
        /// <param name="postData">post数据</param>
        /// <returns>响应数据</returns>
        private string GetHttpResponse(string url, string postData)
        {
            string outputData = string.Empty;
            HttpWebRequest request = GetHttpWebRequest(url);
            if (!string.IsNullOrEmpty(postData))
            {
                using (Stream stream = request.GetRequestStream())
                {
                    byte[] bytes = Encoding.UTF8.GetBytes(postData);
                    stream.Write(bytes, 0, bytes.Length);
                }
            }
            else
            {
                // 无数据时post方式会报错,改为get方式
                request.Method = WebRequestMethods.Http.Get;
            }

            using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
            {
                using (Stream stream = response.GetResponseStream())
                {
                    List<byte> byteList = new List<byte>();
                    byte[] bytes = new byte[Int16.MaxValue];
                    int num = stream.Read(bytes, 0, bytes.Length);
                    while (num > 0)
                    {
                        for (int i = 0; i < num; i++)
                        {
                            byteList.Add(bytes[i]);
                        }
                        num = stream.Read(bytes, 0, bytes.Length);
                    }
                    outputData = Encoding.UTF8.GetString(byteList.ToArray());
                }
            }

            return outputData;            
        }

        private HttpWebRequest GetHttpWebRequest(string url)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
            if (url.StartsWith("https", StringComparison.OrdinalIgnoreCase))
            {
                request = WebRequest.Create(url) as HttpWebRequest;
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
                ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(CheckValidationResult);
                request.ProtocolVersion = HttpVersion.Version10;
            }
            else
            {
                request = WebRequest.Create(url) as HttpWebRequest;
            }

            request.Proxy = null;
            request.Method = WebRequestMethods.Http.Post;
            request.KeepAlive = false;
            return request;
        }

        private bool CheckValidationResult(object sender, System.Security.Cryptography.X509Certificates.X509Certificate certificate, System.Security.Cryptography.X509Certificates.X509Chain chain, SslPolicyErrors sslPolicyErrors)
        {
            return true;
        }
    }
}
View Code

 

<a>标签拥有两个静态伪类:link、:visited,两个动态伪类:hover、:active,另外新添加的动态伪类:focus

1、三种动态均可以作用于其他元素,兼容情况如下:

  a、chrome,ie8+均支持

  b、ie7仅支持:hover

  c、ie6不支持动态伪类

2、注意伪类仅作用于可以拥有焦点的元素,如<input>、<a>等

 

小图标采用背景的方式实现,具体实现方式为<span> &nbsp;</span>,并为span添加padding,注意有两个不同表示的空格,这种方式可以兼容ie6+、chrome

 

以post的方式打开新的页面的方式:

function openPageByPost(url, params, targetName) {
    var $form = $('<form method="post"></form>').attr({ action: url, target: targetName });
    $form.append('<input type="hidden" name="data" value=\'' + params + '\'>');
    $(document.body).append($form);
    $form[0].submit();
    $form.remove();
}
View Code

 

为了实现效果:鼠标移动到按钮显示明细框,移除按钮则隐藏明细框,但从按钮移动到明细框则不隐藏

该效果的关键是使用setTimeout函数,实例代码如下:

            $('.selectBtn').mouseout(function(){
                $('.dateList').attr('show', 'false');
                setTimeout(function(){
                    if($('.dateList').attr('show') == 'false')
                        $('.dateList').hide();
                }, 100);
                
            });
            $('.dateList').mouseover(function(){
                $('.dateList').attr('show', 'true');
            });
            $('.dateList').mouseout(function(){
                $('.dateList').attr('show', 'false');
                setTimeout(function(){
                    if($('.dateList').attr('show') == 'false')
                        $('.dateList').hide();
                }, 100);
            });
View Code

使用setTimeout函数也可实现同一按钮兼容双击事件的效果,实例:jquery 单击和双击事件冲突解决方案

posted @ 2015-07-13 11:42  Matt_Cheng  阅读(294)  评论(0编辑  收藏  举报