菜鸟问个超简单的问题,答对马上就给分
<!----ywb 20071220---->
<style type="text/css">
<!--
#divOptionalMessage1 {
position:absolute;
left: auto;
top: auto;
width:500px;
height:500px;
padding:6px;
z-index:1;
font-weight: bolder;
color: white;
background-color: #006699;
}
-->
</style>
<script language="javascript">
//event.clientX 取得鼠标X轴坐标 IE,Netscap, Firefox 都可以用这个参数
function switchOptMessage(mouseX,mouseY,layerName,isShow){
if(isShow=="show"){
document.all[layerName].style.visibility="visible";
document.all[layerName].style.left=250;
document.all[layerName].style.top=30;
}else{
document.all[layerName].style.visibility="hidden";
}
}
</script>
<div id="divOptionalMessage1" style="visibility:hidden">
<center><IMG src="photo/1.jpg"></center><br>介绍:
</div>
<!----ywb 20071220---->
问题:当有多个相同的divOptionalMessage1,仅仅变化的是<IMG src="photo/x.jpg">,能不能把divOptionalMessage1用数组表示?一个一个写太繁琐,代码太长了------解决方案--------------------用JS输出
JScript code
<script>
for(var i=1;i<=10;i++){
document.write('<div id="divOptionalMessage1" style="visibility:hidden">')
document.write('<center><IMG src="photo/'+i+'.jpg"></center><br>介绍:')
document.write('</div>')
}
</script>
------解决方案--------------------
HTML code
<style type="text/css">
<!--
.divClass {
position:absolute;
left: auto;
top: auto;
width:500px;
height:500px;
padding:6px;
z-index:1;
font-weight: bolder;
color: white;
background-color: #006699;
}
-->
</style>
<script>
for(var i=1;i <=11;i++){
//class="divClass"
document.write('<div class="divClass" id="divOptionalMessage'+i+'" style="visibility:hidden">')
document.write('<center><IMG src="photo/'+i+'.jpg"></center><br> 介绍')
document.write('</div>')
}
</script>