java中怎样生成随机字母?

PS:网页中验证码的水印效果是怎么作出来的?... PS:网页中验证码的水印效果是怎么作出来的? 展开
 我来答
百度网友8dd2c3e41
2007-02-12 · TA获得超过431个赞
知道小有建树答主
回答量:439
采纳率:0%
帮助的人:320万
展开全部
char c=(char) (Math.random ()*26+'a');
System.out.print (c);

参考资料: http://blog.sina.com.cn/u/49e0feb10100077k

已赞过 已踩过<
你对这个回答的评价是?
评论 收起
2382506
2007-02-12 · TA获得超过112个赞
知道答主
回答量:133
采纳率:0%
帮助的人:36.8万
展开全部
function Watermark(imgElement, imgDim)
{
this.imgElement = imgElement; //与水印邦定的图片对象的参考
this.preImgX = imgDim.x; //图片移动前的x坐标
this.preImgY = imgDim.y; //图片移动前的y坐标
this.watermarkElement; //输出后的水印对象的参考
this.id = imgElement.id + "Watermark"; //水印图片的id
this.x = imgDim.x; //水印左上角的x坐标
this.y = imgDim.y; //水印左上角的y坐标
this.zIndex = imgDim.z; //水印的z-index值
}
Watermark.prototype.length = 0; //创建水印对象的总数
Watermark.prototype.img = "images/002.gif"; //所有水印共同使用的水印图片(也可以设置独自的图片)
Watermark.prototype.opacity = 50; //水印的不透明度
Watermark.prototype.width; //水印的宽(创建水印后可获取或自定义)
Watermark.prototype.height; //水印的高(创建水印后可获取或自定义)
Watermark.prototype.locate = "rightBottom"; //水印的位置:leftTop/rightTop/leftBottom/rightBottom
Watermark.prototype.getHTML = function() //返回对应的水印层的HTML代码
{
return "<img src=" + this.img + " id='" + this.id + "' style='position:absolute; z-index:" + this.zIndex + "; left: " + this.x + "px; top: " + this.y + "px;filter:progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=" + this.opacity + ")'>";
}
Watermark.prototype.setWatermarkElement = function() //设定及返回水印对象的参考
{
return eval("this.watermarkElement = document.all." + this.id + ";");
}
Watermark.prototype.setSize = function(width, height) //设定水印的宽和高
{
Watermark.prototype.width = width;
Watermark.prototype.height = height;
}

var watermarkObjs = new Array(); //存放水印对象的数组

function getDim(element)
{
for (var leftX=0,leftY=0,zIndex=0; element!=null; )
{
leftX += element.offsetLeft;
leftY += element.offsetTop;
if (element.tagName != "BODY")
zIndex = element.style.zIndex; //水印的z-index值

element = element.offsetParent;
}

return {x:leftX, y:leftY, z:zIndex} //返回对象的x、y坐标和z-index层数
}

function createWatermark(imgElement, locate)
{
if ( !imgElement ) //如果没有图片不能创建水印
{
return null;
}

var index = watermarkObjs.length; //定义新水印对象的数组索引
var imgDim = getDim(imgElement);
watermarkObjs[index] = new Watermark(imgElement, imgDim); //创建新水印对象到数组中
document.writeln( watermarkObjs[index].getHTML() ); //输出水印层的HTML元素
var wmElement = watermarkObjs[index].setWatermarkElement(); //设定水印对象的参考
watermarkObjs[index].setSize(wmElement.width, wmElement.height);
if ( (locate == "leftTop") || (locate == 1) ||
(locate == "rightTop" ) || (locate == 2) ||
(locate == "leftBottom" ) || (locate == 3) ||
(locate == "rightBottom" ) || (locate == 4) )
{
watermarkObjs[index].locate = locate; //设定水印的位置
}
reviseWatermark(watermarkObjs[index]);
++Watermark.prototype.length;

return watermarkObjs[index]; //返回该水印对象的指针
}

function reviseWatermark(watermarkObj)
{
var imgDim = getDim(watermarkObj.imgElement); //重新取得图片的位置

with (watermarkObj) //调整水印对象的属性值
{
preImgX = imgDim.x;
preImgY = imgDim.y;
switch (locate)
{
case 1:
case "leftTop":
x = imgDim.x;
y = imgDim.y;
break;
case 2:
case "rightTop":
x = imgDim.x + (imgElement.width - width);
y = imgDim.y;
break;
case 3:
case "leftBottom":
x = imgDim.x;
y = imgDim.y + (imgElement.height - height);
break;
case 4:
case "rightBottom":
x = imgDim.x + (imgElement.width - width);
y = imgDim.y + (imgElement.height - height);
break;
}
zIndex = imgDim.z;
}
with (watermarkObj.watermarkElement.style) //调整水印在网页上的位置
{
left = watermarkObj.x;
top = watermarkObj.y;
zIndex = watermarkObj.zIndex;
}

return watermarkObj; //返回该水印对象的指针
}

function reviseWatermark_handy(imgElement)
{
for (var idx=0; idx<watermarkObjs.length; ++idx) //在watermark的对象数组中查找与图片对应的对象
{
if (watermarkObjs[idx].imgElement == imgElement)
{
return reviseWatermark(watermarkObjs[idx]); //把查找到的对象传给reviseWatermark()进行修正
}
}

return null; //查找不到相应的对象返回空
}

function checkWatermark()
{
var imgDim;
for (var idx=0; idx<watermarkObjs.length; ++idx)
{
imgDim = getDim(watermarkObjs[idx].imgElement); //获取图片当前的位置
if ( (imgDim.x != watermarkObjs[idx].preImgX) ||
(imgDim.y != watermarkObjs[idx].preImgY) ||
(imgDim.z != watermarkObjs[idx].zIndex) )
{
reviseWatermark(watermarkObjs[idx]); //修正该水印对象的位置
}
}

return true;
}

window.onresize = checkWatermark;

测试网页代码如下:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> 为网页中的图片添加水印的效果 </title>
<meta name="Generator" content="EditPlus">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<script src="watermark_to_img.js" language="JavaScript"></script>
</head>

<body>
<p>这个程序可以处理图片在网页中比较复杂的定位和多个图片的交错重叠关系,使水印和图片充分地结合在一起!而且可以设定水印在图片上的位置</p>
<table border="1" bgcolor="red">
<tr>
<td width="5%"></td>
<td>这个图片是用表格来定位:<br>
<img src="images/saying1.jpg" width="450" height="313" border="0" alt="" onload="createWatermark(this)">
</td>
<td width="5%"></td>
</tr>
</table>
<p>这个图片在网页中是相对定位:<br>
<img src="images/saying2.jpg" width="462" height="308" border="0" alt="" onload="createWatermark(this,'leftTop')">

<div style="position:absolute; z-index:1; left:400px; top:180px; border: thick double yellow; background-color:yellow" align="right">这个图片是用层来定位的:<br>
<img src="images/saying3.jpg" width="426" height="302" border="0" alt="" onload="createWatermark(this, 'leftBottom')">
</div>
</body>
</html>
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式