js文件里实现点击一个图标,弹出选择图片的对话框

JavaScript06

js文件里实现点击一个图标,弹出选择图片的对话框,第1张

这个功能一般都是html做的。

<form>

<input type="file" />

</form>

呵呵,就这么简单,不过具体传到哪里去,那就是后台人员的事了。

先解压出来 然后放到指定的目录下面

然后src=image/xx.png。

或者加入jstl 标签

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

再如下引用

<img src="<c:url value="/images/R.gif"/>" border="0" alt="设备、零配件">

<html>

<head>

<title>标题页</title>

<meta http-equiv=content-type content="text/htmlcharset=GBK">

<style type="text/css">

A:visited{color:blue}

A:hover{color:red}

A{

TEXT-DECORATION:none

outline:none

}

</style>

<script language="JavaScript">

<!--

// 判断浏览器的变量

IE4 = (navigator.appName == "Microsoft Internet Explorer") ? true : false

// 初始化菜单

function initIt(){

if (!IE4) return

divColl = document.getElementsByTagName("DIV")

for (i=0i<divColl.lengthi++) {

whichele = divColl(i)

if (whichele.className == "child") whichele.style.display = "none"

}

var myLinks = document.links

// 去掉超链接虚边框

for( j=0 j<myLinks.lengthj++){

myLinks[j].onfocus = function(){this.blur()}

}

}

// 展开菜单的方法

function expandIt(ele) {

if (!IE4) return

var name = ele + "Child"

whichele = document.all[name]

if (whichele.style.display == "none") {

whichele.style.display = "block"

}else {

whichele.style.display = "none"

}

}

// 改变链接图片

function changeImg(img){

img.src = (img.src.indexOf("2.jpg") != -1)?"1.jpg":"2.jpg"

}

// 鼠标悬停的时候改变颜色

function mouseOn(obj){

obj.bgColor = "#EFFFFF"

}

// 鼠标离开的时候改变颜色

function mouseOut(obj){

obj.bgColor = "#FFFFFF"

}

onload = initIt

-->

</script>

</head>

<body>

<!--网站收藏-->

<div id="menuParent" class="parent">

<img name="image1" id="image1" src="2.jpg" onClick="expandIt('menu')changeImg(this)" >网站收藏</img>

</div>

<div id="menuChild" class="child">

<table border=0 cellspacing=0 cellpadding=0>

<tr>

<td width=30 align="right">●</td>

<td onmouseover="mouseOn(this)" onmouseout="mouseOut(this)">

<a href="http://www.baidu.com" target="_blank" >百度</a>

</td>

</tr>

</table>

<table border=0 cellspacing=0 cellpadding=0>

<tr>

<td width=30 align="right">●</td>

<td onmouseover="mouseOn(this)" onmouseout="mouseOut(this)">

<a href="http://www.sina.com.cn" target="_blank" >新浪</a>

</td>

</tr>

</table>

<table border=0 cellspacing=0 cellpadding=0>

<tr>

<td width=30 align="right">●</td>

<td onmouseover="mouseOn(this)" onmouseout="mouseOut(this)">

<a href="http://www.sohu.com" target="_blank" >搜狐</a>

</td>

</tr>

</table>

</div>

<!--文本区域-->

<div id="Menu2Parent" class="parent">

<img name="image1" id="image1" src="2.jpg" onClick="expandIt('Menu2')changeImg(this)" >文本区域</img>

</div>

<div id="Menu2Child" class="child">

<table border=0 cellspacing=0 cellpadding=0>

<tr>

<td width="30"> </td>

<td onmouseover="mouseOn(this)return false" onmouseout="mouseOut(this)return false">

<a href="#" onclick="expandIt('Menu21')">文章一</a>

</td>

</tr>

</table>

<div id="Menu21Child" class="child" style="width:260">

<table border=0 cellspacing=0 cellpadding=0>

<tr>

<td width="30"></td>

<td bgColor="DFFFFF">

JavaScript是目前web应用程序开发者使用最为广泛...

</td>

</tr>

</table>

</div>

<table border=0 cellspacing=0 cellpadding=0>

<tr>

<td width="30"> </td>

<td onmouseover="mouseOn(this)return false" onmouseout="mouseOut(this)return false">

<a href="#" onclick="expandIt('Menu22')">文章二</a>

</td>

</tr>

</table>

<div id="Menu22Child" class="child" style="width:260">

<table border=0 cellspacing=0 cellpadding=0>

<tr>

<td width="30"></td>

<td bgColor="DFFFFF">

20世界90年代中期,大部分互联网用户使用28.8kb/s......

</td>

</tr>

</table>

</div>

<table border=0 cellspacing=0 cellpadding=0>

<tr>

<td width="30"> </td>

<td onmouseover="mouseOn(this)return false" onmouseout="mouseOut(this)return false">

<a href="#" onclick="expandIt('Menu23')">文章三</a>

</td>

</tr>

</table>

<div id="Menu23Child" class="child" style="width:260">

<table border=0 cellspacing=0 cellpadding=0>

<tr>

<td width="30"></td>

<td bgColor="DFFFFF">

在接下来的几年时间里,ISO/IEC采纳ECMAScript作为.....

</td>

</tr>

</table>

</div>

</div>

<!--多层菜单演示-->

<div id="Menu3Parent" class="parent">

<img name="image1" id="image1" src="2.jpg" onClick="expandIt('Menu3')changeImg(this)" >多层菜单演示</img>

</div>

<div id="Menu3Child" class="child">

<table border=0 cellspacing=0 cellpadding=0>

<tr>

<td width=30> </td>

<td>

<!--start-->

<div id="Menu3Parent" class="parent">

<img name="image1" id="image1" src="2.jpg" onClick="expandIt('Menu4')changeImg(this)" >多层</img>

</div>

<div id="Menu4Child" class="child">

<table border=0 cellspacing=0 cellpadding=0>

<tr>

<td width=30>&nbsp</td>

<td onmouseover="mouseOn(this)" onmouseout="mouseOut(this)">

<a href="#">子菜单一</a>

</td>

</tr>

<tr>

<td>&nbsp</td>

<td onmouseover="mouseOn(this)" onmouseout="mouseOut(this)">

<a href="#">子菜单二</a>

</td>

</tr>

<tr>

<td>&nbsp</td>

<td onmouseover="mouseOn(this)" onmouseout="mouseOut(this)">

<a href="#">子菜单三</a>

</td>

</tr>

</table>

</div>

<!--end-->

</td>

</tr>

</table>

<table border=0 cellspacing=0 cellpadding=0>

<tr>

<td width=30> </td>

<td onmouseover="mouseOn(this)" onmouseout="mouseOut(this)">

<a href="#">子菜单二</a>

</td>

</tr>

</table>

<table border=0 cellspacing=0 cellpadding=0>

<tr>

<td width=30> </td>

<td onmouseover="mouseOn(this)" onmouseout="mouseOut(this)">

<a href="#">子菜单三</a>

</td>

</tr>

</table>

</div>

</body>

</html>

这是我写的一个小例子

图片是截取的qq的那个菜单图标,你可以自己弄