给你个提示,我是用以下方法实现的: <% word="h a n g h w p" shuzu=split(word," ",-1,1) a= ubound(shuzu)-lbound(shuzu) ss="" for i=0 to a ss=ss&(shuzu(i)&" ") next response.Write(ss) %> 有点缺点就是在输入的时候必须保留一个空格/用于后面的分离!现在只要能把这用空字符替换就行了 可是我试了下换成 word="hanghwp" shuzu=split(word,"",-1,1) 就不正常了/看看其他人还有什么办法!
随手写了一个:P <div align=center id=mm style="border: 1px solid red"></div> <input id=txt value="分散对齐,期待绝对高手"><input type=button value=run onclick="run()"> <SCRIPT LANGUAGE="JavaScript"> function run() { var e = document.all.txt var s = e.value.replace(/(^\s+)|(\s+$)/, ""); if(s=="") return false; //得到空格的宽度 document.all.mm.innerHTML = "<span id=hehe> </span>"; var spaceWidth = document.all.hehe.offsetWidth; //得到文字的宽度 document.all.mm.innerHTML = "<span id=hehe>"+ s +"</span>"; var txtWidth = document.all.hehe.offsetWidth; var w = document.all.mm.offsetWidth; var divider = Math.floor((w - txtWidth)/(spaceWidth*(s.length-1))); var space = ""; for(var i=0; i<divider; i++) space += " "; s = s.substring(0,1) + s.substr(1).replace(/(.)/g, space +"$1"); document.all.mm.innerHTML = s; } </SCRIPT>
<script language=vbscript> function chk() if len(tomuno.tom.value)<1 then msgbox("输入完整信息") return false end if st end function sub st() v=tomuno.tom.value for i=1 to len(v) tmp=tmp&" "&mid(v,i,1) next tomuno.tom.value=tmp end sub </script> <form name="tomuno"> <input type="text" name="tom" value="a大22撒1ds"> <input type="button" onclick=st() value=click> <input type="submit" value=submit> </form>
别人的我没看,我的试过了,是在表单提交的时候先把值改了再提交。<script language=vbscript> function chk()
if len(tomuno.tom.value)<1 then msgbox("输入完整信息") return false end if st end function sub st() v=tomuno.tom.value for i=1 to len(v) tmp=tmp&" "&mid(v,i,1) next tomuno.tom.value=tmp end sub </script> <form name="tomuno" onsubmit="return chk()"> <input type="text" name="tom" value="a大22撒1ds"> <input type="button" onclick=st() value=click> <input type="submit" value=submit> </form>
<%
word="h a n g h w p"
shuzu=split(word," ",-1,1)
a= ubound(shuzu)-lbound(shuzu)
ss=""
for i=0 to a
ss=ss&(shuzu(i)&" ")
next
response.Write(ss)
%>
有点缺点就是在输入的时候必须保留一个空格/用于后面的分离!现在只要能把这用空字符替换就行了
可是我试了下换成
word="hanghwp"
shuzu=split(word,"",-1,1)
就不正常了/看看其他人还有什么办法!
<div align=center id=mm style="border: 1px solid red"></div>
<input id=txt value="分散对齐,期待绝对高手"><input type=button value=run onclick="run()">
<SCRIPT LANGUAGE="JavaScript">
function run()
{
var e = document.all.txt
var s = e.value.replace(/(^\s+)|(\s+$)/, "");
if(s=="") return false; //得到空格的宽度
document.all.mm.innerHTML = "<span id=hehe> </span>";
var spaceWidth = document.all.hehe.offsetWidth; //得到文字的宽度
document.all.mm.innerHTML = "<span id=hehe>"+ s +"</span>";
var txtWidth = document.all.hehe.offsetWidth; var w = document.all.mm.offsetWidth;
var divider = Math.floor((w - txtWidth)/(spaceWidth*(s.length-1)));
var space = "";
for(var i=0; i<divider; i++) space += " ";
s = s.substring(0,1) + s.substr(1).replace(/(.)/g, space +"$1");
document.all.mm.innerHTML = s;
}
</SCRIPT>
function chk()
if len(tomuno.tom.value)<1 then
msgbox("输入完整信息")
return false
end if
st
end function
sub st()
v=tomuno.tom.value
for i=1 to len(v)
tmp=tmp&" "&mid(v,i,1)
next
tomuno.tom.value=tmp
end sub
</script>
<form name="tomuno">
<input type="text" name="tom" value="a大22撒1ds">
<input type="button" onclick=st() value=click>
<input type="submit" value=submit>
</form>
function chk()
if len(tomuno.tom.value)<1 then
msgbox("输入完整信息")
return false
end if
st
end function
sub st()
v=tomuno.tom.value
for i=1 to len(v)
tmp=tmp&" "&mid(v,i,1)
next
tomuno.tom.value=tmp
end sub
</script>
<form name="tomuno" onsubmit="return chk()">
<input type="text" name="tom" value="a大22撒1ds">
<input type="button" onclick=st() value=click>
<input type="submit" value=submit>
</form>