文本中首字母全改为大写
2001-01-07 10:14:48 来源:WEB开发网核心提示:脚本说明: 第一步:把如下代码加入<head>区域中 <SCRipT LANGUAGE="javaScript"> <!-- Begin function changeCase(frmObj) { var index; var tmpStr; var tmpChar;
脚本说明:
第一步:把如下代码加入<head>区域中
<SCRipT LANGUAGE="javaScript">
<!-- Begin
function changeCase(frmObj) {
var index;
var tmpStr;
var tmpChar;
var PReString;
var postString;
var strlen;
tmpStr = frmObj.value.toLowerCase();
strLen = tmpStr.length;
if (strLen > 0) {
for (index = 0; index < strLen; index++) {
if (index == 0) {
tmpChar = tmpStr.substring(0,1).toUpperCase();
postString = tmpStr.substring(1,strLen);
tmpStr = tmpChar + postString;
}
else {
tmpChar = tmpStr.substring(index, index+1);
if (tmpChar == " " && index < (strLen-1)) {
tmpChar = tmpStr.substring(index+1, index+2).toUpperCase();
preString = tmpStr.substring(0, index+1);
postString = tmpStr.substring(index+2,strLen);
tmpStr = preString + tmpChar + postString;
}
}
}
}
frmObj.value = tmpStr;
}
// End -->
</script>
第二步:把如下代码加入<body>区域中
<form name=form>
<input type=text name=box value="type in here!">
<input type=button value="Convert" onClick="Javascript:changeCase(this.form.box)">
</form>
第一步:把如下代码加入<head>区域中
<SCRipT LANGUAGE="javaScript">
<!-- Begin
function changeCase(frmObj) {
var index;
var tmpStr;
var tmpChar;
var PReString;
var postString;
var strlen;
tmpStr = frmObj.value.toLowerCase();
strLen = tmpStr.length;
if (strLen > 0) {
for (index = 0; index < strLen; index++) {
if (index == 0) {
tmpChar = tmpStr.substring(0,1).toUpperCase();
postString = tmpStr.substring(1,strLen);
tmpStr = tmpChar + postString;
}
else {
tmpChar = tmpStr.substring(index, index+1);
if (tmpChar == " " && index < (strLen-1)) {
tmpChar = tmpStr.substring(index+1, index+2).toUpperCase();
preString = tmpStr.substring(0, index+1);
postString = tmpStr.substring(index+2,strLen);
tmpStr = preString + tmpChar + postString;
}
}
}
}
frmObj.value = tmpStr;
}
// End -->
</script>
第二步:把如下代码加入<body>区域中
<form name=form>
<input type=text name=box value="type in here!">
<input type=button value="Convert" onClick="Javascript:changeCase(this.form.box)">
</form>
[]
更多精彩
赞助商链接