Posted on 2006-10-19 16:56
王孝强 阅读(479)
评论(0) 编辑 收藏 所属分类:
编程技术
各位高手们,这里我向大家请教一下:Js中汉字转成首字母。望赐教与交流,QQ:35366866
利用VBscript和JavaScript将汉字转成汉字首字母(代码1:zhifu.js)。我把它写成Js文件文件(去掉和不去掉<script>两种情况都试了),将其Link到要用的页面,不好使。但是将代码直接写入要引用的页面就好使。不知道为什么?但直接写入后,另一个按比例缩放图片的JS(代码2:changeImg)就不好使了。
引用过程如下:先被代码3(JS)引用,因为要转化的东西是一个变量,代码3负责提取出变量。然后代码4(JSP引用)。
还有个问题,改变图片大小的changeImg函数,用onload的形式加载(如代码所示)。如果要改变的图片尺寸有点太大的时候(比如七八百像素),加载网页时,图片先显示原始大小,然后一闪而过缩小为我要的80*80的图片。这样,很难看,不知道是不是机器运行速度的问题。如果一个页面需要改变的图片很多的话,那就更难看。
我也试过
http://topic.csdn.net/t/20030402/16/1610083.html
中的方法,我用时这个方法不行,图片大小都改不了。
代码3
function showSimpleinfo(arr)
{
ar = arr;
var ss = document.getElementById('simpleinfo');
var s = '';
s += '<TABLE id=header style="HEIGHT: 30px" cellSpacing=0 cellPadding=0 width="100%"><TBODY>';
s += '<TR vAlign=bottom height=15>';
s += '<TD width="764" height="28" align=left background=about/tr3.gif>';
s += ' <span class="head3top2">' + arr[0];
s += '</span> <span class="head3top2">' +
getpy(arr[0]);
s += '</span><span class="head3top1"> '+ arr[8] +'</span></TD>';
................................
s += '<tr><td bgcolor="#F0E8F5" rowspan="4" width="40"> </td>';
s += '<td bgcolor="#F0E8F5" height="80" width="80" valign="center" rowspan="4">';
s += '<img border="0" src="pictureDownload?userId='+userid+'" onload=
changeImg(this)></
td>';
(不知道为什么影响它了)
代码4
</head>
<body onload="show()">
<div id = "simpleinfo"></div><br>
<table cellpadding="0" cellspacing="0" width="968" height="586">
<!-- MSTableType="layout" -->
<tr>
<td width="166" height="20" valign="top">
<div id="test"></div>
<div class='CNLTreeMenu' id='CNLTreeMenu1'></div>
<p> </td>
<td valign="top" width="12">
</td>
<td valign="top" width="746">
<div id="content"> </div></td>
<td valign="top" height="586" width="42"> </td>
</tr>
</table>
这个simpleinfo指向代码3
代码1:
<script language="vbscript" runat="server">
Function getAsc(str)
getAsc=Asc(str)
End Function
</script>
<script language="javascript" runat="server">
function getpy(str){
var result="";
if (typeof(str)!="string") str=new String(str);
var tmp = 65536 + getAsc(str.substr(0,1));
/*var uc=str.charCodeAt(0);
if (uc<128){
if ((uc>=65&&uc<=90)||(uc>=97&&uc<=122)||(uc>=48&&uc<=57))
{
return str.substr(0,1).toUpperCase();
}
else
{ return "";
}
}*/
if(tmp>=45217&&tmp<=45252) {
result= "A";
}else if(tmp>=45253&&tmp<=45760) {
result= "B";
}else if(tmp>=45761&&tmp<=46317) {
result= "C";
}else if(tmp>=46318&&tmp<=46825) {
result= "D";
}else if(tmp>=46826&&tmp<=47009) {
result= "E";
}else if(tmp>=47010&&tmp<=47296) {
result= "F";
}else if(tmp>=47297&&tmp<=47613) {
result= "G";
}else if(tmp>=47614&&tmp<=48118) {
result= "H";
}else if(tmp>=48119&&tmp<=49061) {
result= "J";
}else if(tmp>=49062&&tmp<=49323) {
result= "K";
}else if(tmp>=49324&&tmp<=49895) {
result= "L";
}else if(tmp>=49896&&tmp<=50370) {
result= "M";
}else if(tmp>=50371&&tmp<=50613) {
result= "N";
}else if(tmp>=50614&&tmp<=50621) {
result= "O";
}else if(tmp>=50622&&tmp<=50905) {
result= "P";
}else if(tmp>=50906&&tmp<=51386) {
result= "Q";
}else if(tmp>=51387&&tmp<=51445) {
result= "R";
}else if(tmp>=51446&&tmp<=52217) {
result= "S"
}else if(tmp>=52218&&tmp<=52697) {
result= "T";
}else if(tmp>=52698&&tmp<=52979) {
result= "W";
}else if(tmp>=52980&&tmp<=53640) {
result= "X"
}else if(tmp>=53689&&tmp<=54480) {
result= "Y";
}else if(tmp>=54481&&tmp<=62289) {
result= "Z";
}else{
result=str.substr(0,1).toUpperCase();
}
return result;
}
代码2
function changeImg(mypic){
var xw=80;
var xl=80;
var width = mypic.width;
var height = mypic.height;
var bili = width/height;
var A=xw/width;
var B=xl/height;
if(A<1||B<1)
{
if(A<=B)
{
mypic.width=xw;
mypic.height=xw/bili;
}
if(A>B)
{
mypic.width=xl*bili;
mypic.height=xl;
}
}
}