代码小技巧

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方法是将一个对象的方法在另一个对象的上下文环境中执行


 5、管理端使用了富文本编辑器后将说明信息维护到数据库中,保存的字符串中当然包含了html标签。将数据取出保存到前台js对象中后,取得时候发现字符串中的html标签已经被转义掉了,显示到页面后又被解析回来显示成了html字符串,为了解决这一问题:


$("#xksm_text").html($("<div/>").html(top.xksz['xksm']).text());

 

//核心解决方法:$("<div/>").html(encodedStr).text();

 6、截取字符串最后一位。

   方法一:运用String对象下的charAt方法  str.charAt(str.length – 1)

  方法二:运用String对象下的substr方法 str.substr(str.length-1,1)

 方法三:运用String对象下的split方法 var str = “123456″; spstr = str.split(“”);spstr[spstr.length-1];

今天解决Ext一个小问题:

设置Ext中comboxBox下拉框的默认值,同事使用setValue结果下拉组件直接显示了value而不是displayValue;

解决方法是:

combo.store.on('load',function(store,records,opts){
	Ext.each(records,function(rec){
		if(rec.data.VALUE == 需要作为默认值的变量){
			combo.setValue(?);//设置值
			combo.setRawValue(?);//设置显示值
		}
	});
});
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值