社区
JavaScript
帖子详情
怎样将一个全角字符转换成半角的呢? Javascript中text有style属性吗?是什么意思,怎么用呢?
lionet777
2002-04-17 04:25:51
怎样将一个全角字符转换成半角的呢?
Javascript中text有style属性吗?是什么意思,怎么用呢?
...全文
127
7
打赏
收藏
怎样将一个全角字符转换成半角的呢? Javascript中text有style属性吗?是什么意思,怎么用呢?
怎样将一个全角字符转换成半角的呢? Javascript中text有style属性吗?是什么意思,怎么用呢?
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用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
打赏
举报
回复
不可能作吧。。。除非一个一个字符地查表。
JavaScript
全角
转
半角
部分
通过扩展String对象的原型,增加
一个
名为`dbc2sbc`的函数,可以将
字符
串
中
的
全角
字符
转换为
半角
字符
。 ```
javascript
String.prototype.dbc2sbc=function() { return this.replace(/[\uff01-\uff5e]/g, function(a...
关于脚本操作文本域的问题
在网页开发
中
,文本域(`<
text
area>`)是
一个
常见的元素,用于用户输入多行文本。当用户在文本域
中
输入内容,浏览器会自动处理换行,特别是在文本达到指定宽度时进行自动回行。然而,这些自动换行在存储到数据库和...
javaScript
把
全角
转换成
半角
一、用JS把
全角
转换成
半角
(不能转换标点符号)onkeyup="
javascript
:var t = ; with(this.value) { for (var i = 0; i />二、用JS把
全角
转换成
半角
的函数function CtoH(obj){ var str=obj.value;var result="";for ...
JS
全角
自动
转换成
半角
的几种方式
JS
全角
自动
转换成
半角
的几种方式
输入的
全角
字符
转换成
半角
字符
--css、js、ASP.NET
我们经常需要用户在表单
中
输入数字,用户不小心使用了
全角
状态输入数字,但是在程序
中
全角
的数字是不能直接转换为数字的。这种
全角
数字的错误处理起来就有些麻烦了。对一些没有经验用户来说明明已经输入数字了,怎么...
JavaScript
87,996
社区成员
224,693
社区内容
发帖
与我相关
我的任务
JavaScript
Web 开发 JavaScript
复制链接
扫一扫
分享
社区描述
Web 开发 JavaScript
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章