#if 使您可以开始条件指令,测试一个或多个符号以查看它们是否计算为 true。如果它们的计算结果确实为true,则编译器将计算位于 #if 与最近的 #endif 指令之间的所有代码。例如,
1 #if DEBUG
2 string file = root + "/conf_debug.xml";
3 #else
4 string file = root + "/conf.xml";
5 #endif
这段代码会像往常那样编译,但读取debug配置文件包含在#if子句内。这行代码只有在前面的#define命令定义了符号DEBUG后才执行。当编译器遇到#if语句后,将先检查相关的符号是否存在,如果符号存在,就只编译#if块中的代码。否则,编译器会忽略所有的代码,直到遇到匹配的#endif指令为止。一般是在调试时定义符号DEBUG,把不同的调试相关代码放在#if子句中。在完成了调试后,就把#define语句注释掉,所有的调试代码会奇迹般地消失,可执行文件也会变小,最终用户不会被这些调试信息弄糊涂(显然,要做更多的测试,确保代码在没有定义DEBUG的情况下也能工作)。这项技术在C和C++编程中非常普通,称为条件编译(conditional compilation)。
参考msdn实例:
1 // preprocessor_if.cs
2 #define DEBUG
3 #define VC_V7
4 using System;
5 public class MyClass
6 {
7 static void Main()
8 {
9 #if (DEBUG && !VC_V7)
10 Console.WriteLine("DEBUG is defined");
11 #elif (!DEBUG && VC_V7)
12 Console.WriteLine("VC_V7 is defined");
13 #elif (DEBUG && VC_V7)
14 Console.WriteLine("DEBUG and VC_V7 are defined");
15 #else
16 Console.WriteLine("DEBUG and VC_V7 are not defined");
17 #endif
18 }
19 }
输出结果:
DEBUG and VC_V7 are defined
花了一上午时间,终于写了一个进行排序并且分页的类,下面将代码贴出来,望大家指正。
1 /* 系统名:SaleManage
2 * 模块名:SortPags
3 * 模块说明:排序分页类(传入DataTable,及相关信息,然后分页,并排序)
4 * 开发者:Peter Luo
5 * 开发时间:2012年4月6日
6 */
7 using System;
8 using System.Collections.Generic;
9 using System.Linq;
10 using System.Text;
11 using System.Data ;
12
13 namespace Sale_Core
14 {
15 public class SortPags
16 {
17 /// <summary>
18 /// 存储传入的数据
19 /// </summary>
20 private DataTable _DtSource = null;
21 private DataView _DvSource = null;
22
23 /// <summary>
24 /// 分页排序类
25 /// </summary>
26 /// <param name="dt">要分页或排序的数据源</param>
27 public SortPags(DataTable dt)
28 {
29 this._DtSource = dt;
30 }
31
32 /// <summary>
33 /// 分页排序类
34 /// </summary>
35 /// <param name="dv">要分页或排序的数据源</param>
36 public SortPags(DataView dv)
37 {
38 this._DvSource = dv;
39 }
40
41 /// <summary>
42 /// 页面总数
43 /// </summary>
44 private int _PageCount;
45
46 /// <summary>
47 /// 每页记录数量
48 /// </summary>
49 private int _PageSiz;
50
51 /// <summary>
52 /// 记录总数
53 /// </summary>
54 private int _RowCount;
55
56 /// <summary>
57 /// 排序类型
58 /// ASC 升序
59 /// DESC 降序
60 /// </summary>
61 private SortType _SortKind;
62
63 /// <summary>
64 /// 记录当前页面Index
65 /// </summary>
66 private int _CurrentPageIndex;
67
68 /// <summary>
69 /// 数据源
70 /// </summary>
71 public DataTable DtSource
72 {
73 get
74 {
75 return _DtSource;
76 }
77 }
78
79 /// <summary>
80 /// 页面数量
81 /// </summary>
82 public int PageCount
83 {
84 get
85 {
86 return _PageCount;
87 }
88 }
89
90 /// <summary>
91 /// 页面显示数量
92 /// </summary>
93 public int PageSize
94 {
95 get
96 {
97 return _PageSiz;
98 }
99 set
100 {
101 _PageSiz = value;
102 }
103 }
104
105 /// <summary>
106 /// 只读、不能写,获取该数据源那数据总数
107 /// </summary>
108 public int RowCount
109 {
110 get
111 {
112 return _RowCount;
113 }
114 }
115
116 public SortType SortKind
117 {
118 get
119 {
120 return _SortKind;
121 }
122 set
123 {
124 _SortKind = value;
125 }
126 }
127
128 /// <summary>
129 /// 记录当前页面Index
130 /// </summary>
131 public int CurrentPageIndex
132 {
133 get
134 {
135 return _CurrentPageIndex;
136 }
137 }
138
139 public DataView Sort(string sortName, SortType sortKind)
140 {
141 return new DataView();
142 }
143
144 /// <summary>
145 /// 获取按照给定字段分页后的制定页,(排序->分页)
146 /// </summary>
147 /// <param name="sortName">传入排序的字段</param>
148 /// <param name="sortKind">排序的类型:SortType.ASC 升序 SortType.DESC 降序</param>
149 /// <param name="pageSize">页面的大小(页面内要显示的记录的数量)</param>
150 /// <param name="currentPageIndex">当前页面的index</param>
151 /// <returns></returns>
152 public DataTable GetCurrentPageSortByFileName(string sortName, SortType sortKind, int pageSize, int currentPageIndex)
153 {
154 if (pageSize == 0)
155 return DtSource;//如果没有填写pagesize那么返回整个数据源
156 if (currentPageIndex <= 0)
157 return DtSource; //如果没有传入当前页面index,则返回整个数据源
158 if (sortName == "")
159 return GetCurrentPage(pageSize, currentPageIndex);//如果排序字段没写,则只有分页,不进行排序
160
161 DataView dv = new DataView(DtSource);
162 switch (sortKind)
163 {
164 case SortType.DESC :
165 dv.Sort = sortName + "DESC";
166 break;
167 case SortType .ASC :
168 dv.Sort = sortName + "ASC";
169 break;
170 default :
171 break;
172 }
173
174 _PageSiz = pageSize;
175 _CurrentPageIndex = currentPageIndex;
176
177 this._RowCount = this.DtSource.Rows.Count;
178 this._PageCount = this.RowCount / this.PageSize;
179 if (_PageCount * PageSize < RowCount) //如果计算出的页面数*页面上的数据量小于记录数,那么页面大小自动+1
180 {
181 _PageCount++;
182 }
183
184 int currentBeginRowIndex = pageSize * (currentPageIndex - 1); //当前页面的开始行
185 int currentEndRowIndex = pageSize * currentPageIndex - 1;//当前页面的结束行
186 DataTable dtRes = _DtSource.Clone(); //复制数据源表结构
187 for (int i = currentBeginRowIndex; i <= currentEndRowIndex; i++) //复制当前页面的数据到新的datatable中
188 {
189 if (i >= DtSource.Rows.Count)
190 break; //当前页面的记录小于该页面应该显示的记录时,就只取当前页面中的数据
191 DataRow dr = dtRes.NewRow();
192 for (int j = 0; j < _DtSource.Columns.Count; j++)
193 {
194 dr[j] = dv[i][j];
195 }
196 dtRes.Rows.Add(dr);
197 }
198 return dtRes;
199 }
200
201 /// <summary>
202 ///
203 /// </summary>
204 /// <param name="pageSize">每页面大小(每个页面上记录的数量)</param>
205 /// <param name="currentPageIndex">当前页面索引</param>
206 /// <returns></returns>
207 public DataTable GetCurrentPage(int pageSize, int currentPageIndex)
208 {
209 if (pageSize ==0)
210 {
211 return DtSource;//如果没有填写pagesize那么返回整个数据源
212 }
213 if (currentPageIndex <= 0)
214 {
215 return DtSource;//如果没有传入当前页面index,则返回整个数据源
216 }
217 _PageSiz = pageSize;
218
219 _CurrentPageIndex = currentPageIndex;
220 this._RowCount = this.DtSource.Rows.Count;
221 this._PageCount = this.RowCount / this.PageSize;
222 if (_PageCount * PageSize < RowCount) //如果计算出的页面数*页面上的数据量小于记录数,那么页面大小自动+1
223 _PageCount++;
224 int CurrentBeginRowIndex = PageSize * (currentPageIndex - 1); //当前页面的开始行
225 int CurrentEndRowIndex = PageSize * currentPageIndex - 1; //当前页面的结束行
226 DataView dv;
227 if (_DvSource == null)
228 dv = new DataView(DtSource);
229 else
230 dv = _DvSource;
231 DataTable dtRes = _DtSource.Clone(); //复制数据源表结构
232 for (int i = CurrentBeginRowIndex; i <= CurrentEndRowIndex; i++) //复制当前页面的数据到新的datatable中
233 {
234 if (i >= DtSource.Rows.Count) break; //当前页面的记录小于该页面应该显示的记录时,就只取当前页面中的数据
235 DataRow dr = dtRes.NewRow();
236 for (int j = 0; j < _DtSource.Columns.Count; j++)
237 {
238 dr[j] = dv[i][j];
239 }
240 dtRes.Rows.Add(dr);
241 }
242 return dtRes;
243 }
244 public enum SortType
245 {
246 ASC, //升序排列
247 DESC //倒序排列
248 }
249 }
250 }
get方法中只有一个参数,这个参数是混合参数,可以是DOM节点的id、也可以是一个Element、或者是一个DOM节点对象等。看下面的示例代码:
Ext.onReady(function(){
var e=new Ext.Element("hello");
alert(Ext.get("hello"));
alert(Ext.get(document.getElementById("hello")));
alert(Ext.get(e));
});
Html页面中包含一个id为hello的div,代码如下:
<div id="hello">tttt</div>
Ext.onReady(function(){
var h=new Ext.Panel({
id:"h2",
title:" ",
renderTo:"hello",
width:300,
height:200});
Ext.getCmp("h2").setTitle("新的标题");
});
Ext.onReady(function(){
var e=new Ext.Element("hello");
Ext.getDom("hello");
Ext.getDom(e);
Ext.getDom(e.dom);
});
Html:
<div id="hello">tttt</div>
Ext.onReady(function(){
var h=new Ext.Panel({title:"测试",width:300,height:200});
h.render(Ext.getBody());
});

开发者在做Web开发时,往往会遇到一些开发问题,也许您会通过Google或者查看编程词典来寻求解决方法。今天,我们将为您提供一份非常有价值的速查表,包含JavaScript、MYSQL、PHP、CSS、HTML5、RGB Hex Color Codes等等,您只需要收藏此页,即可轻松访问,赶紧收藏吧!>>>点击图片即可查看大图。
一、PHP
二、MYSQL
三、JavaScript
四、CSS
五、Regular Expression
六、Apache’s mod_rewrite

七、HTML
八、HTML Character Entities
九、RGB Hex Color Codes
十、jQuery
十一、SEO

此图片为pdf格式,点击这里查看大图
十二、HTML5


十四、WordPress

十五、Subversion
十六、 Eclipse


十八、Twitter

十九、CakePHP

原文地址:http://zhaodehai.com/archives/256
- C# code
-
using System.Collections.Generic;
-
using System.IO;
-
using System.Linq;
-
using System.Net;
-
using System.Text;
-
namespace Youku
-
{
-
/// <summary>
-
/// 优酷热门视频实体类
-
/// </summary>
-
public class YouHotVideo
-
{
-
public string Title { get; set; }
-
public string ImgURI { get; set; }
-
public string URI { get; set; }
-
public YouHotVideo(string title, string imgUri, string uri)
-
{
-
Title = title;
-
ImgURI = imgUri;
-
URI = uri;
-
}
-
public static List<YouHotVideo> GetALL()
-
{
-
var v = new StreamReader(HttpWebRequest.Create(“http://www.youku.com”) .GetRespons()
-
.GetResponseStream(), Encoding.UTF8).ReadToEnd() .Replace(“<li “, “❇”).Split(‘❇’)
-
.Where(x => x.Contains(“v_link”) || x.Contains(“v_thumb”)) .Select(x => x.Substring(x.IndexOf(“http”)))
-
.Select(x => x.Remove(x.IndexOf(“>”))).ToList();
-
-
v = v.Select(x => x + v.ElementAt(v.IndexOf(x) + (v.IndexOf(x) == v.Count() – 1 ? 0 : 1))).ToList();
-
-
return v.Where(x => v.IndexOf(x) % 2 == 0).Where(x => x.Contains(“html”) && x.Contains(“ykimg”))
-
.Select(x => x.Replace(“<”, “<”).Replace(“>”, “>”).Replace(“"”, “\”") .Replace(“ ”, ” “))
-
.ToList().Select(x => new YouHotVideo(x.Remove(x.LastIndexOf(“\”")) .Substring(x.IndexOf(“title”) + 7), x.Remove((x.Contains(“src”) ? x.LastIndexOf(” src”) : x .LastIndexOf(” alt”)) – 1)
-
.Substring(x.IndexOf(“ykimg”) – 10), x.Remove(x.IndexOf(“html”) + 4))).ToList();
-
}
-
}
}
- C# code
-
using System;
-
namespace ConsoleApplicationDemo
-
{
-
class Program
-
{
-
static void Main(string[] args)
-
{
-
Youku.YouHotVideo.GetALL().ForEach(x => { Console.WriteLine(“标题:” + x.Title);
-
Console.WriteLine(“图片地址:” + x.ImgURI);
-
Console.WriteLine(“视频地址:” + x.URI); Console.WriteLine();
-
});
-
Console.ReadLine();
-
}
-
}
-
}

原文地址:http://zhaodehai.com/archives/258。
自定义主要通过两种方式实现
$.extend({aa:function(){}});
$.fn.extend({aa:function(){}});
调用的方法分别是:
$.aa();
$($this).aa();
注意:
创建函数时不要放在 $(function() { }中,调用时候要放在事件里面
$($this).click(function(){$.aa();});
jQuery.extend 函数详解
JQuery的extend扩展方法:
Jquery的扩展方法extend是我们在写插件的过程中常用的方法,该方法有一些重载原型,在此,我们一起去了解了解。
一、Jquery的扩展方法原型是:
var result=$.extend({},{name:"Tom",age:21},{name:"Jerry",sex:"Boy"})
那么合并后的结果
result={name:"Jerry",age:21,sex:"Boy"}
也就是说后面的参数如果和前面的参数存在相同的名称,那么后面的会覆盖前面的参数值。
二、省略dest参数
上述的extend方法原型中的dest参数是可以省略的,如果省略了,则该方法就只能有一个src参数,而且是将该src合并到调用extend方法的对象中去,如:
1、$.extend(src)
该方法就是将src合并到jquery的全局对象中去,如:
hello:function(){alert('hello');}
});
2、$.fn.extend(src)
该方法将src合并到jquery的实例对象中去,如:
hello:function(){alert('hello');}
});
就是将hello方法合并到jquery的实例对象中。
下面例举几个常用的扩展实例:
这是在jquery全局对象中扩展一个net命名空间。
hello:function(){alert('hello');}
})
这是将hello方法扩展到之前扩展的Jquery的net命名空间中去。
三、Jquery的extend方法还有一个重载原型:
第一个参数boolean代表是否进行深度拷贝,其余参数和前面介绍的一致,什么叫深层拷贝,我们看一个例子:
{ name: "John", location: {city: "Boston",county:"USA"} },
{ last: "Resig", location: {state: "MA",county:"China"} } );
我们可以看出src1中嵌套子对象location:{city:"Boston"},src2中也嵌套子对象location:{state:"MA"},第一个深度拷贝参数为true,那么合并后的结果就是:
location:{city:"Boston",state:"MA",county:"China"}}
也就是说它会将src中的嵌套子对象也进行合并,而如果第一个参数boolean为false,我们看看合并的结果是什么,如下:
{ name: "John", location:{city: "Boston",county:"USA"} },
{ last: "Resig", location: {state: "MA",county:"China"} }
);
以上就是$.extend()在项目中经常会使用到的一些细节。
电话号码正则表达式:
1 /**
2 * 手机号码
3 * 移动:134[0-8],135,136,137,138,139,150,151,157,158,159,182,187,188
4 * 联通:130,131,132,152,155,156,185,186
5 * 电信:133,1349,153,180,189
6 */
7
8 String MOBILE = "^1(3[0-9]|5[0-35-9]|8[025-9])\\d{8}$";
9
10 /**
11 * 中国移动:China Mobile
12 * 134[0-8],135,136,137,138,139,150,151,157,158,159,182,187,188
13 */
14
15 String CM = "^1(34[0-8]|(3[5-9]|5[017-9]|8[278])\\d)\\d{7}$";
16
17 /**
18 * 中国联通:China Unicom
19 * 130,131,132,152,155,156,185,186
20 */
21
22 String CU = "^1(3[0-2]|5[256]|8[56])\\d{8}$";
23
24 /**
25 * 中国电信:China Telecom
26 * 133,1349,153,180,189
27 */
28
29 String CT = "^1((33|53|8[09])[0-9]|349)\\d{7}$";
30
31 /**
32 * 大陆地区固话及小灵通
33 * 区号:010,020,021,022,023,024,025,027,028,029
34 * 号码:七位或八位
35 */
36
37 String PHS = "^0(10|2[0-5789]|\\d{3})\\d{7,8}$";











