手机浏览 RSS 2.0 订阅 膘叔的简单人生 , 腾讯云RDS购买 | 超便宜的Vultr , 注册 | 登陆
浏览模式: 标准 | 列表2008年11月25日的文章

jQuery的html()等方法介绍

本来是看到一篇文章,写研究的,想COPY过来就完事了。该来来自于cssRain,但是在看的过程中,发现内容和标准偏差很多,于是就贴上它的链接,然后自己谈谈理解吧。

CSSRAIN的链接为:http://www.cssrain.cn/article.asp?id=1176

在jQuery里面对于一些HTML的元素操作都是很简化的,这也是很多人选择使用jQuery的原因。

对于获取某一个元素的值,如input框,我们往往是用$('#test').val();

$('#test')这个我就不多说了,反正就是获取ID为test的这个元素。

$('#test').val(),也就是获取它的值,一般来说,凡是能够用在FORM里的元素,都可以用.val()来进行值的获取,如input,textarea,select等,都可以用.val()来获取它们的当前值

而.val('aa');则是设置该元素的值,$('#test').val('aa'),也就是相当于设置test元素的值为aa。

类似这样的用法还有两种:.html(),.text(),这两种用法往往用在div和span元素上,一般是为这两种元素进行赋值和取值。

.html()替代了以前的 .innerHTML , .html('test') ,则是替代了 .innerHTML = 'test';

这些类似的简化写法让我们在实际的操作中感觉得更加流畅。

这些方法都是直接在方法名里加参数来进行赋值和取值的。还有一些是通过第二个参数进行取值的(说的不太清楚。。。),比如$('#test').attr('name'),那么,返回的值就是它的attribute中的name了,如果$('#test').attr('id','test2'),则是相当于把这个test元素的name设为test2,再进行取值的时候,name就是test2了。

说的太乱了。。。。

懒得整理,权当笔记

Tags: jquery, html, 研究

PDF下载:《High Performance MySQL》

回忆未来的张宴推荐了这本书,并且在他的博客上提供了下载的链接,链接是新浪的爱问:点此下载《High Performance MySQL Second Edition》PDF电子版,并且博客上还有详细介绍:

  XML/HTML代码

  1. High Performance MySQL Second Edition  
  2. 作者: Baron Schwartz / Peter Zaitsev / Vadim Tkachenko / Jeremy Zawodny / Arjen Lentz / Derek Balling  
  3.   
  4. 副标题: Optimization, Backups, Replication, and More  
  5. ISBN: 9780596101718  
  6. 页数: 708  
  7. 定价: USD 49.99  
  8. 出版社: O'Reilly Media, Inc.  
  9. 装帧: Paperback  
  10. 出版年: 2008-06-18  
  11.   
  12. High Performance MySQL is the definitive guide to building fast, reliable systems with MySQL. Written by noted experts with years of real-world experience building very large systems, this book covers every aspect of MySQL performance in detail, and focuses on robustness, security, and data integrity.  
  13.   
  14. High Performance MySQL teaches you advanced techniques in depth so you can bring out MySQL's full power. Learn how to design schemas, indexes, queries and advanced MySQL features for maximum performance, and get detailed guidance for tuning your MySQL server, operating system, and hardware to their fullest potential. You'll also learn practical, safe, high-performance ways to scale your applications with replication, load balancing, high availability, and failover.  
  15.   
  16. This second edition is completely revised and greatly expanded, with deeper coverage in all areas. Major additions include:  
  17. * Emphasis throughout on both performance and reliability  
  18. * Thorough coverage of storage engines, including in-depth tuning and optimizations for the InnoDB storage engine  
  19. * Effects of new features in MySQL 5.0 and 5.1, including stored procedures, partitioned databases, triggers, and views  
  20. * A detailed discussion on how to build very large, highly scalable systems with MySQL  
  21. * New options for backups and replication  
  22. * Optimization of advanced querying features, such as full-text searches  
  23. * Four new appendices  
  24. The book also includes chapters on benchmarking, profiling, backups, security, and tools and techniques to help you measure, monitor, and manage your MySQL installations.  

为此,张宴还提供了一张图片:

 

大小: 5.18 K
尺寸: 106 x 139
浏览: 1841 次
点击打开新窗口浏览全图

 

整篇博客我作了一下整理和排序,想看原文的,请到:http://blog.s135.com/read.php?381,因为在这个页面上张宴采用了划词翻译,如果有看不懂英文的话,选中一下就会自动翻译了。。我没有提供。也不想再插入一些代码。呵呵

为了方便大家,我也上传了这个文件,大家可以点击下载:high.performance.mysql_second.edition.zip


Tags: mysql, database, pdf, download

MySQL之表结构修改[转]

Author:丹臣 posted on Taobao.com

mysql数据库里,对一个已创建的表进行DDL操作,比如说添加一个字段。在做测试时,发现ddl操作的时间特别的长。oracle里,通常情况下只是 修改数据字典就可以了,操作时间非常的短,阻塞DML的时间也比较短。mysql数据库对表进行ddl操作跟oracle数据库有很大的不同,它先要把原 表拷贝一份到临时表,这期间不阻塞select,阻塞所有的更改操作(update,delete,insert),对临时表ddl操作完成,删除原表, 重命名临时表。
如果一张比较大的表进行ddl变更,比如说40G,那拷贝的时间让人无法忍受,并且阻塞所有的DML操作,让业务无法继续。

以下是测试过程:

mysql> desc t1;
+-------------------+------------------+------+-----+---------+-------+
| Field                  | Type               | Null   | Key | Default | Extra |
+-------------------+------------------+------+-----+---------+-------+
| id                      | int(11)            | YES  | MUL | NULL    |       |
| nick                   | varchar(32)   | YES  |         | NULL    |       |
| email                 | varchar(32)    | YES  |         | NULL    |       |
| gmt_create       | datetime         | YES  |         | NULL    |       |
| gmt_modified    | datetime        | YES  |         | NULL    |       |
+-------------------+------------------+------+-----+---------+-------+
mysql> select count(*) from t1;
+----------+
| count(*) |
+----------+
|  2228017 |
+----------+
1 row in set (1.78 sec)

现在对它进行表结构变更,增加一列:

mysql> alter table t1 add(tel varchar(20));
Query OK, 2304923 rows affected (41.03 sec)
Records: 2304923  Duplicates: 0  Warnings: 0

在上述表结构变更过程中,启动另外一个会话,进行select查询操作和一个更新操作:

mysql> select count(*) from t1;
+---------------+
| count(*)      |
+---------------+
|  2304923     |
+---------------+
1 row in set (2.10 sec)

mysql> select * from t1 limit 10;
+------+-------+------------------------+----------------------------+----------------------------+
| id      | nick   | email                       | gmt_create                 | gmt_modified              |
+------+-------+------------------------+----------------------------+----------------------------+
|    0   | nick0 | nick0@taobao.com | 2008-03-14 00:00:00 | 2008-03-14 00:00:00 |
|    1   | nick1 | nick1@taobao.com | 2008-03-14 00:00:00 | 2008-03-14 00:00:00 |
|    2   | nick2 | nick2@taobao.com | 2008-03-14 00:00:00 | 2008-03-14 00:00:00 |
|    3   | nick3 | nick3@taobao.com | 2008-03-14 00:00:00 | 2008-03-14 00:00:00 |
|    4   | nick4 | nick4@taobao.com | 2008-03-14 00:00:00 | 2008-03-14 00:00:00 |
|    5   | nick5 | nick5@taobao.com | 2008-03-14 00:00:00 | 2008-03-14 00:00:00 |
|    6   | nick6 | nick6@taobao.com | 2008-03-14 00:00:00 | 2008-03-14 00:00:00 |
|    7   | nick7 | nick7@taobao.com | 2008-03-14 00:00:00 | 2008-03-14 00:00:00 |
|    8   | nick8 | nick8@taobao.com | 2008-03-14 00:00:00 | 2008-03-14 00:00:00 |
|    9   | nick9 | nick9@taobao.com | 2008-03-14 00:00:00 | 2008-03-14 00:00:00 |
+------+-------+------------------------+----------------------------+----------------------------+
10 rows in set (0.00 sec)

mysql> update t1 set nick='test_nick' where id=1;
Query OK, 4 rows affected (43.89 sec)          --这里是阻塞的时间
Rows matched: 4  Changed: 4  Warnings: 0

通过以上实验可以看出,对表进行ddl操作时,mysql并不阻塞select查询,但会严重阻塞dml操作。另外,如果你要对表进行ddl操作,由于有一个拷贝操作,你要计算好你的可用空间够不够?如果你的系统经常要进行表结构变更,那么你将不得不要考虑此问题!

--EOF--

膘叔:说实话,一般对于表的操作往往都是在夜深人静的时候,虽然select并不影响,但为避免在更新表结构的时候更新数据,这还是必须的。。。以防万一啊

 

Tags: mysql, database, 修改, 表结构, taobao dba

XML to JSON plugin--把xml转化为json插件

以前用JS操作XML都是用DOM的方式,现在有了这个插件,操作起来会更方便了直接采用对象。。。

来源:http://www.94this.com.cn/article/258.htm

这个插件应该是比较方便的一个插件了,它能把xml字符串或xml文件转化为json对象,比如把

XML/HTML代码
  1. <xml>  
  2. <message>Hello world</message>  
  3. </xml>  

转化为
JavaScript代码
  1. {  
  2.     message: 'Hello world';  
  3. }  

这样我们操作起来就很方便了,因为用javascript操作json比操作xml要方便好多。

基本的使用:

JavaScript代码
  1. var xml = '<xml><message>Hello world</message></xml>';  
  2. var json = $.xml2json(xml);  
  3. alert(json.message);  

当然它也能通过直接把xml文件转化为json:

JavaScript代码
  1. $.get('data/hello.xml'function(xml){  
  2.     var json = $.xml2json(xml);  
  3.     alert(json.message);  
  4. });  

好了,看看基本的演示吧!(膘叔:演示地址仍然是亮亮的网站)

这个插件还有一个扩展的用法:
基本的是把

XML/HTML代码
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <animals>  
  3. <dog color='Black'>  
  4.   <name>Rufus</name>  
  5.   <breed>labrador</breed>  
  6. </dog>  
  7. <dog breed='whippet'>  
  8.   Adopted  
  9.   <name>Marty</name>  
  10. </dog>  
  11. <cat color="White">  
  12.   <name>Matilda</name>  
  13. </cat>  
  14. </animals>  
转化为 
JavaScript代码
  1. {    
  2.    dog:[    
  3.      { name:'Rufus', breed:'labrador', color:'Black' },    
  4.      { text:'Adopted', name:'Marty', breed:'whippet' }    
  5.    ],    
  6.    cat:{ name:'Matilda', color:'White'}    
  7. }   
扩展的作用是把每个节点转化为数组的形式,即
JavaScript代码
  1. {    
  2.    dog:[    
  3.      { name:['Rufus'], breed:['labrador'], color:'Black' },    
  4.      { text:'Adopted', name:['Marty'], breed:'whippet' }    
  5.    ],    
  6.    cat:[    
  7.      { name:'Matilda', color:'White'}    
  8.    ]    
  9. }   

这个使用也简单,就多了一个参数:

JavaScript代码
  1. $.get('data/animals.xml'function(xml){  
  2.    var animals = $.xml2json(xml, true);  
  3.    alert(animals.dog[1].name[0].text +'/'+ animals.dog[1].text);  
  4. });  


最后,看看所有用法的演示(此演示官方提供)吧!