摘要: 这是来到这里的第一篇文章 为了纪念 也为了开始!纪念我的红尘 开始我的一叶一花!阅读全文
posted @ 2012-02-10 18:02 lcyang 阅读(7) 评论(0) 编辑
摘要: Makefile一:Makefile的规则:target...:prerequisites...command......target也就是一个目标文件,可以是ObjectFile,也可以是执行文件。还可以是一个标签(Label)prerequisites就是要生成那个target所需要的文件或是目标。command也就是make需要执行的命令。(任意的Shell命令)这是一个文件的依赖关系,也就是说target这一个或多个的目标文件依赖于prerequisites中的文件,其生成规则定义在command中。说白一点就是说,prerequisites中如果有一个以上的文件比target文件要新阅读全文
posted @ 2012-02-29 19:52 lcyang 阅读(71) 评论(0) 编辑

bind()方法的其它用法

发表于   admin

bind()方法不仅能为元素绑定浏览器支持的具有相同名称的事件,也可以绑定自定义事件。不仅如此,bind()方法还能做很多的事情。

1.绑定多个事件类型

例如可以为元素一次性绑定多个事件类型。jQuery代码如下:

$(function () {
    $("div").bind("mouseover mouseout", function () {
        $(this).toggleClass("over");
    });
})

当光标插入div元素时,该元素的class切换为“over”;当光标画出“div”元素时,class切换为先前的值。这段代码等同于下面的代码:

$(function () {
    $("div").bind("mouseover", function () {
        $(this).toggleClass("over");
    }).bind("mouseout", function () {
        $(this).toggleClass("over");
    });
})

很显然,第一种方法能减少代码量。

2.添加事件命名空间,便于管理

例如可以把元素绑定的多个事件类型用于命名空间规范起来,jQuery代码如下:

$(function () {
    $("div").bind("click.plugin", function () {
        $("body").append("<p>click 事件</p>");
    });
    $("div").bind("mouseover.plugin", function () {
        $("body").append("<p>mouseover事件</p>");
    });
    $("div").bind("dblclick", function () {
        $("body").append("<p>dblclick事件</p>")
    });
    $("button").click(function () {
        $("div").unbind(".plugin");
    });
})

在所绑定的事件类型后面添加命名空间,这样在删除事件时只需要指定命名空间即可。单击button元素后,“plugin”的命名空间被删除,而不在“plugin”的命名空间“dblclick”事件依然存在。

删除多个事件代码也可以写为以下链式代码,但显然下面的方式写的更少。

$("div").unbind("click").unbind("mouseover");

3.相同事件名称,不同命名空间执行方法

例如可以为元素绑定相同的事件类型,然后以命名空间的不同按需要调用,jQuery代码如下:

$(function () {
    $("div").bind("click", function () {
        $("body").append("<p>click 事件</p>");
    });
    $("div").bind("click.plugin", function () {
        $("body").append("<p>click.plugin</p>");
    });
    $("button").click(function () {
        $("div").trigger("click!"); //注意click后面的感叹号
    });
})

当单击div元素后,会同时触发click事件和click.plugin事件。如果知识单击button元素,则只触发click.plugin事件。注意,trigger(“click!”)后面的感叹号的作用是匹配多有不包含在命名空间中的click方法。

如果需要两者都被触发,改为如下代码即可:

$("div").trigger("click"); // 去掉感叹号
posted @ 2012-02-21 15:50 lcyang 阅读(21) 评论(0) 编辑

编辑器加载中...

 1 <html>
2 <head>
3 <!--get() 方法获得由选择器指定的 DOM 元素。-->
4 <script type = "text/javascript" src = "jquery.js"></script>
5 <script type = "text/javascript">
6 $(document).ready(function(){
7 $("button").click(function(){
8 x = $("p").get();
9 for(var i = 0;i<x.length;i++){
10 document.write(x[i].innerHTML+"/");
11 }
12 alert(x)
13 });
14 });
15 </script>
16 </head>
17 <body>
18 <p>this</p>
19 <p>this</p>
20 <p>this</p>
21 <p>this</p>
22 <p>this</p>
23 <p>this</p>
24 <button type = "button">click</button>
25 </body>
posted @ 2012-02-21 14:26 lcyang 阅读(8) 评论(0) 编辑
View Code
 1 #-*- coding:utf8-*-
2 import time
3 start = time.time()
4
5 from urllib2 import Request,urlopen
6 from urllib import quote_plus
7 info='the flowers are on their way'
8 url='http://www.pythonchallenge.com/pc/stuff/violin.php'
9 req = Request(url, headers={'Cookie': 'info=' + quote_plus(info)})
10 print urlopen(req).read()
11
12 print "耗时:"+str(time.time() - start)
posted @ 2012-02-10 18:35 lcyang 阅读(10) 评论(0) 编辑
View Code
 1 #-*- coding:utf8-*-
2 import time
3 start = time.time()
4 '''
5 import xmlrpclib
6
7 server = xmlrpclib.ServerProxy("http://localhost:80")
8
9 words = server.sayHello()
10
11 print "result:" + words
12 '''
13 import xmlrpclib
14 server = xmlrpclib.ServerProxy("http://www.pythonchallenge.com/pc/phonebook.php")
15 words = server.phone('Bert')
16 print words
17 #555-ITALY
18 print "耗时:"+str(time.time() - start)
posted @ 2012-02-10 18:34 lcyang 阅读(9) 评论(0) 编辑
View Code
 1 #-*- coding:utf8-*-
2 import time
3 start = time.time()
4 '''
5 import xmlrpclib
6
7 server = xmlrpclib.ServerProxy("http://localhost:80")
8
9 words = server.sayHello()
10
11 print "result:" + words
12 '''
13 import xmlrpclib
14 server = xmlrpclib.ServerProxy("http://www.pythonchallenge.com/pc/phonebook.php")
15 words = server.phone('Bert')
16 print words
17 #555-ITALY
18 print "耗时:"+str(time.time() - start)
posted @ 2012-02-10 18:32 lcyang 阅读(10) 评论(0) 编辑
View Code
 1 #-*- coding:utf8-*-
2 import time
3 start = time.time()
4 '''
5 import xmlrpclib
6
7 server = xmlrpclib.ServerProxy("http://localhost:80")
8
9 words = server.sayHello()
10
11 print "result:" + words
12 '''
13 import xmlrpclib
14 server = xmlrpclib.ServerProxy("http://www.pythonchallenge.com/pc/phonebook.php")
15 words = server.phone('Bert')
16 print words
17 #555-ITALY
18 print "耗时:"+str(time.time() - start)
posted @ 2012-02-10 18:32 lcyang 阅读(6) 评论(0) 编辑
View Code
 1 #-*- coding:utf8-*-
2 import time
3 start = time.time()
4
5 # Get the data from: http://www.pythonchallenge.com/pc/return/evil2.gfx
6
7 h = open("evil2.gfx", "rb")
8 data = h.read()
9 h.close()
10
11 new_data = [[], [], [], [], []]
12 n = 0
13
14 for byte in range(len(data) - 1):
15 new_data[n].append(data[byte])
16 n = 0 if n == 4 else n + 1
17
18 for n, elt in enumerate(new_data):
19 h = open(str(n + 1), "wb")
20 h.write("".join(elt))
21 h.close()
22
23 print "耗时:"+str(time.time() - start)
posted @ 2012-02-10 18:31 lcyang 阅读(8) 评论(0) 编辑
View Code
 1 #-*- coding:utf8-*-
2 import time
3 start = time.time()
4
5 import Image
6
7 # download the image from: http://www.pythonchallenge.com/pc/return/cave.jpg
8
9 image = Image.open("cave.jpg")
10 nsize = tuple([x / 2 for x in image.size])
11 odd = even = Image.new(image.mode, nsize)
12
13 for x in range(image.size[0]):
14 for y in range(image.size[1]):
15 if x % 2 == 0 and y % 2 == 0:
16 even.putpixel((x / 2, y / 2), image.getpixel((x, y)))
17 elif x % 2 == 0 and y % 2 == 1:
18 odd.putpixel((x / 2, (y - 1) / 2), image.getpixel((x, y)))
19 elif x % 2 == 1 and y % 2 == 0:
20 even.putpixel(((x - 1) / 2, y / 2), image.getpixel((x, y)))
21 else:
22 odd.putpixel(((x - 1) / 2, (y - 1) / 2), image.getpixel((x, y)))
23
24 even.save("even.jpg")
25 odd.save("odd.jpg")
26 print "耗时:"+str(time.time() - start)
posted @ 2012-02-10 18:30 lcyang 阅读(6) 评论(0) 编辑
 1 #-*- coding:utf8-*-
2 import time
3 import re
4 start = time.time()
5 '''
6 a = [1, 11, 21, 1211, 111221,
7 len(a[30]) = ?
8 '''
9
10 def find_L(st):
11 nums = re.findall(r'1+|2+|3+|',st)
12 strs = ''
13 for i in nums:
14 if len(i):
15 strs += str(len(i)) + i[0]
16 return strs
17
18 i = 0
19 s = "1"
20 while i < 30:
21 s = find_L(s)
22 i += 1
23 print i
24 print len(s)
25 #5808
26 #耗时:0.0136680603027
27 print "耗时:"+str(time.time() - start)
posted @ 2012-02-10 18:28 lcyang 阅读(10) 评论(0) 编辑