我只会回答你的第2问,Javascript中text是有style属性的(不光它,还有好多元素都有样式的),用法如<input type=text style="color=red;background:yellow;border:1px,1px,1px,1px;">等等
解决方案 »
- 如何构造函数
- JS 服务端打开IE
- 火狐中js写xml文件
- 写一个HTML页面,实现以下功能,左键点击页面时显示“您好”,右键点击时显示“禁止右键”。并在2分钟后自动关闭页面
- Dojo中文开发手册 推荐下载
- 请问一个正则表达式怎么写
- (在线等)如何获取execcommand('insertimage',true,'')中得到的图片路径呀?
- 怎样把客户端安装的打印机全部列举出来
- 简单问题
- 在XP系统中,ueditor图片上传控制台报错errorHandler is not defined
- 用window.open弹出一个窗口,不管什么分辨率都可以使该窗口位于屏幕中央,怎么写?
- 文字全角,半角的转换该怎么做?
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<meta name="author" content="chueh">
<meta name="keywords" content="软件, 程序设计, 书签, 电子, 电脑, 计算机, 等级考试, 考试, 健身, 钱龙, 读物, 键盘, 自动, 链接, 太极, 气功, 鹊桥, software, program, computer, midi, taijiquan, books, DOS, Windows, ASP, JAVA, javascript">
<title>全角转半角 - que.126.com</title>
</head><script language="JavaScript">
function o2c(fm){
temp=repl(",",", ",document.replace.source.value)
temp=repl("。",". ",temp)
temp=repl("“",' "',temp)
temp=repl("”",'" ',temp)
temp=repl("/","/",temp)
temp=repl("‘","'",temp)
temp=repl("’","'",temp)
//temp=repl("、",". ",temp)
temp=repl("("," (",temp)
temp=repl(")",") ",temp)
temp=repl("*","*",temp)
temp=repl("+","+",temp)
temp=repl("-","-",temp)
temp=repl(";","; ",temp)
temp=repl(":",": ",temp)
temp=repl("[","[",temp)
temp=repl("]","]",temp)
temp=repl("{","{",temp)
temp=repl("}","}",temp)
temp=repl("!","! ",temp)
temp=repl("%","%",temp)
temp=repl("#","#",temp)
temp=repl("¥","$",temp)
temp=repl("…","..",temp)
temp=repl("—","--",temp)
temp=repl("=","=",temp)
temp=repl("·",".",temp)//A:%uFF21 A:%41
//a:%uFF41 a:%61
//0:%uFF10 0:%30for(var i=0;i<26;i++){
temp=repl(unescape("%uff"+hex(33+i)),unescape("%"+hex(65+i)),temp);
temp=repl(unescape("%uff"+hex(65+i)),unescape("%"+hex(97+i)),temp);
}
for(var i=0;i<10;i++)
temp=repl(unescape("%uff"+hex(16+i)),unescape("%"+hex(48+i)),temp);document.replace.target.value=temp;
return true;
}function hex(d){
h1=Math.round(d/16-0.5)
h2=d-h1*16
return ""+d2h(h1)+d2h(h2)
}function d2h(d){
if(d>9) h=unescape("%"+(d-10+41))
else h=""+d
return h
}function repl(str1,str2,tmp){
//str1=fm.replSour.value
//str2=fm.replTarget.value
//tmp=document.replace.source.value
result=""
fmLen=tmp.length
if(fmLen=0) { //无内容
return '';
}
strEnd=tmp.indexOf(str1)
str1Len=str1.length
i=0
while(strEnd>=0){
i++
result = result + tmp.substring(0,strEnd)+str2
tmp=tmp.substring(strEnd+str1Len,tmp.length)
strEnd=tmp.indexOf(str1)
}
result=result+tmp;
if(document.replace.ul[0].checked) result=result.toLowerCase();
if(document.replace.ul[1].checked) result=result.toUpperCase();
return result;
}
</script>
<center>
<BODY onLoad="replace.source.focus()"><FORM NAME="replace">
对结果进行:<input type=radio name=ul>大写->小写
<input type=radio name=ul>小写->大写
<input type=radio name=ul checked>大小写不转换 <input type=reset value=" 清空内容 " onClick="replace.source.focus()"><br>
<textarea name="source" rows=11 cols=80 onblur="o2c(this.form);return true">
</textarea><br>
<textarea name="target" rows=11 cols=80>
</textarea>
</FORM></center>
</BODY></HTML>
我其实是想实现这样的功能,就是:
--------------------------
在一个文本框里,maxlength为20,可以输入20个半角字符,但当输入的为全角字符的时候,只能输入10个.
-------------------------
但是现在我无论输入半角,全角,都可以输入20个!!!!
前面已经注解了:
//A:%uFF21 A:%41
//a:%uFF41 a:%61
//0:%uFF10 0:%30这是他们的 escape 码,网页的一种加密编码,用unescape 进行解码。
全角的字母数字前面都带有 %uFF 后面是有规律的数字,
作者利用了这一点, 是匠心独具!方便之极。