[转]JavaScript中的trim函数
/**
* 去除多余空格函数
* trim:去除两边空格 lTrim:去除左空格 rTrim: 去除右空格
* 用法:
* var str = " hello ";
* str = str.trim();
*/
String.prototype.trim = function()
{
return this.replace(/(^[\\s]*)|([\\s]*$)/g, "");
}
String.prototype.lTrim = function()
{
return this.replace(/(^[\\s]*)/g, "");
}
String.prototype.rTrim = function()
{
return this.replace(/([\\s]*$)/g, "");
}
相关文档:
JavaScript中的对象
关键词: JavaScript 对象 ......
要想写出跨浏览器的javascript,就必须懂得嗅探技术。这是浏览器大战遗留下的大地雷,事已如此,只好认命,乖乖写分支结构吧,函数就是这样不知不觉中变长的。
先看单一浏览器的判断,我们没有必须去找navigator.userAgent的麻烦,我在国外的博客网站收集了如下hack,短小精悍:
ie = !+"\v1" ;
ie ='\v'=='v' ; ......
自己写的一个简易计时器,能记算代码的执行时间,还可以拿来测试代码的执行效率。
function Counter(){
this.start();
}
Counter.prototype.getTime = function(){
var time = new Date();
return time.getSeconds()*1000+time.getMilliseconds();
}
Counter.prototype.start = function(){
this. ......
<!--
/* Font Definitions */
@font-face
{font-family:宋体;
panose-1:2 1 6 0 3 1 1 1 1 1;
mso-font-alt:SimSun;
mso-font-charset:134;
mso-generic-font-family:auto;
mso-font-pitch:variable;
mso-font-signature:3 135135232 16 0 262145 0;}
@font-face
{font-family:"\@宋体" ......
srcElement 是Dom事件中的事件最初指派到的元素。
比如有一个div,里面有一个按钮。你响应div的onclick事件,但实际上,你单击的只是它内部的按钮,那么,srcElement指向的,就是那个按钮。
srcElement只在IE中有效。
在Opera系列浏览器中对应的属性是target
给你一个IE下使用的例子。
<!DOCTYPE html PUBLIC "-//W ......