读书人

代码小技艺

发布时间: 2012-08-15 16:57:17 作者: rapoo

代码小技巧

1、Ext面板中的工具栏

tbar里是按钮居右的符号是“->”,分隔符是“-”。

?

Ext.onReady(function(){var panel = new Ext.Panel({             renderTo:"myPanel",          id : "testPanel",          autoWidth  : true,             autoHeight : true,             autoScroll : true,          frame:false,          border : false,          margins : '0 0 0 0',          split : true,             minHeight : 100,             autoHeight : true,           tbar : [{                   iconCls: 'icon-add',                   text : '添加'            },{                iconCls: 'icon-remove',                   text : '移除'            }]          });          panel.tbar.dom.align = 'center';});

2、去除字符串空格,空格出现的位置分别为前中后,下面分别有两种方式处理

?

方式一(无法处理中间的空格)str=str.replace(/(^\s*)|(\s*$)/g,"");//replace(/(^\s*)/g, "") 去左空格//replace(/(\s*$)/g, "") 去右空格方式二(包括中间的空格)function doTrim(str,is_global) { var result; result = str.replace(/(^\s+)|(\s+$)/g,""); if(is_global.toLowerCase()=="g") result = result.replace(/\s/g,""); return result; } 


3、屏蔽文本框的字符键(输入框只接受数字)

?

function checkNumb(){if (event.keyCode < 45 || event.keyCode > 57)  event.returnValue = false;}

?4、javascript call函数的标准解释:call方法是将一个对象的方法在另一个对象的上下文环境中执行

读书人网 >其他相关

热点推荐