javascript常用代码(去字串两端空格、文本域光标定位到最后)
来源:互联网 发布:最新ip代理搜索软件 编辑:程序博客网 时间:2024/05/16 06:05
//去字串两端空白
function trim(str){
if(null==str) return null;var tmp = str.replace(/(^\s*)|(\s*$)/g, "");
return tmp;
}
//去字串所有空白
function trimAll(str){
var tmp = str.replace(/\s*/g, "");
return tmp;
}
alert("["+opMap.trim(" 23 ssew \n\t")+"]");
alert("["+opMap.trimAll(" 23 ssew \n\t")+"]");
或
String.prototype.trim=function(){
return this.replace(/(^\s*)|(\s*$)/g, "");
};
String.prototype.trimAll=function(){
return this.replace(/\s*/g, "");
};
alert("["+" 23 ssew \n\t".trim()+"]");
alert("["+" 23 ssew \n\t".trimAll()+"]");
//文本域光标定位到最后
function moveTextAreaFocusToLast(){
//文本域对象
var obj=document.getElementById("txtAreaContent");
obj.focus();
var len = obj.value.length;
if (document.selection) {
var sel = obj.createTextRange();
sel.moveStart('character',len);
sel.collapse();
sel.select();
} else if (typeof obj.selectionStart == 'number' && typeof obj.selectionEnd == 'number') {
obj.selectionStart = obj.selectionEnd = len;
}
}
参考:http://www.cainiao8.com/web/js_note/js_regular_expression.html
- javascript常用代码(去字串两端空格、文本域光标定位到最后)
- JavaScript使光标定位到文本的最后
- JavaScript使光标定位到文本的最后
- js使光标定位到文本的最后
- js 去两端空格
- js去两端空格
- 可编辑的div,focus之后,光标怎么定位到文本最后
- 文本框获取焦点后如何将光标定位到文本最后
- 光标定位到文本的末尾
- C# textbox中光标定位到最后一行
- 将EditText的光标定位到字符的最后面
- input、textarea、div(contenteditable=true)光标定位到最后
- JavaScript去掉两端空格方法
- javascript 去除字符串两端空格
- 把焦点光标移动到id的文本最后
- DevExpress 9.1 MemoEdit (textBox) 定位光标到文本结尾
- 光标定位到输入框文本的尾端
- 怎样把光标定位到TextField文本的末尾位置
- Linux内核驱动之GPIO子系统(一)GPIO的使用
- 软件测试这回事
- Hbase源码研究(四)------put(2)
- 11-分类和协议
- 寒假打工去,不能继续写博客,表示好心痛啊。。。
- javascript常用代码(去字串两端空格、文本域光标定位到最后)
- BB10 Cascades: 如何消除“Unresolved inclusion”警告信息
- UI界面类项目 demo
- 关于 ulimit -SHn 65535
- 关于SO动态库的两个搜索路径
- zoj1542Network
- 数据挖掘:Top 10 Algorithms 序
- Android中的签名机制
- Linux系统节拍定时器(system tick timer)