怎样将一个全角字符转换成半角的呢? Javascript中text有style属性吗?是什么意思,怎么用呢?

lionet777 2002-04-17 04:25:51
怎样将一个全角字符转换成半角的呢?
Javascript中text有style属性吗?是什么意思,怎么用呢?
...全文
127 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
mosane 2002-04-24
  • 打赏
  • 举报
回复

前面已经注解了:
//A:%uFF21 A:%41
//a:%uFF41 a:%61
//0:%uFF10 0:%30

这是他们的 escape 码,网页的一种加密编码,用unescape 进行解码。
全角的字母数字前面都带有 %uFF 后面是有规律的数字,
作者利用了这一点, 是匠心独具!方便之极。

lionet777 2002-04-23
  • 打赏
  • 举报
回复
unescape("%uff"+hex(33+i)),中的%uff 是干什么的呢??
我其实是想实现这样的功能,就是:
--------------------------
在一个文本框里,maxlength为20,可以输入20个半角字符,但当输入的为全角字符的时候,只能输入10个.
-------------------------
但是现在我无论输入半角,全角,都可以输入20个!!!!
weidegong 2002-04-17
  • 打赏
  • 举报
回复
<html><head>
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<meta name="author" content="chueh">
<meta name="keywords" content="软件, 程序设计, 书签, 电子, 电脑, 计算机, 等级考试, 考试, 健身, 钱龙, 读物, 键盘, 自动, 链接, 太极, 气功, 鹊桥, software, program, computer, midi, taijiquan, bookmarks, 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:%30

for(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>
seabell 2002-04-17
  • 打赏
  • 举报
回复
我只会回答你的第2问,Javascript中text是有style属性的(不光它,还有好多元素都有样式的),用法如<input type=text style="color=red;background:yellow;border:1px,1px,1px,1px;">等等
孟子E章 2002-04-17
  • 打赏
  • 举报
回复
正则表达式替换!
lionet777 2002-04-17
  • 打赏
  • 举报
回复
啊,真的做不到吗?
有没有这种转换的方法?
wizz 2002-04-17
  • 打赏
  • 举报
回复
不可能作吧。。。除非一个一个字符地查表。

87,996

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧