<html>
<head>
<title>测试字符串</title>
<script>
//去空白prototype
String.prototype.trim = function() {
return this.replace(/(^\s*)|(\s*$)/g, "");
}
//去空白方法
function trim(str) {
return str.replace(/(^\s*)|(\s*$)/, "");
}
var s = " 123uuuuu ";
alert(s.slice(4, 11));
alert(s.slice(4, 11).length);
alert(s.length);
alert(s.trim().length);
alert(trim(s).length);
alert(trim(s));
var phoneNumOrg = "(130) 51570789";
if(phoneNumOrg != null && phoneNumOrg != "" && phoneNumOrg.length >= 7){
var phoneNum = phoneNumOrg.slice(1,4) + phoneNumOrg.slice(6);
alert("phoneNum: " + phoneNum);
}
function openModelSMSWin(){
var url="http://www.baidu.com";
var nLeft = ( window.screen.width + 300 )/2;
var nTop = ( window.screen.height - 200 )/2;
var sStyle="width=430px,height=290px,left="+nLeft+"px,top="+nTop+"px,scrollbars=no,resizable=no,menubar=no,status=no, location=no";
window.open(url,"即时短信", sStyle);
}
</script>
</head>
<body>
<input type="button" value="模板" onclick="openModelSMSWin();" />
</body>
</html>
js字符串大小写转换
var str = "aaaa";
alert(str.toLowerCase());
alert(str.toUpperCase());
本文介绍了JavaScript中字符串的多种操作方法,包括去除空白字符、截取特定部分、大小写转换等,并展示了如何处理电话号码格式及打开窗口的具体实现。
1242

被折叠的 条评论
为什么被折叠?



