头像图片的选择,如何存到数据库

1.javascript中写函数

<script type="text/javascript">
	function ShowImage(page, tag) {
		var i = 1;
		var e;
		var a;
		while (e = document.getElementById(tag + i)) {
			a = "image/" + i + ".jpg";
			if (a == page)
				e.style.display = 'block';
			else
				e.style.display = 'none';
			i++;
		}
	}
</script>

 2.在body里面写HTML代码

<%String i = "image/3.jpg";%>
<%String j = "image/2.jpg";%>
<%String k = "image/1.jpg";%>
<tr>
	<td>头像:</td>
	<td align="left">
	<div style="display: block" id="image1">
	<img src=<%=j%> width="70" height="77" />
	</div>
	<div style="display: none" id="image2">
	<img src=<%=k%> width="70" height="77" />
	</div>
	<div style="display: none" id="image3">
	<img src=<%=i%> width="70" height="77" />
	</div>
	</td>
	<td><select name="head" onchange="ShowImage(this.value, 'image');">
	<option selected="selected" value=<%=i%>>头像一 </option>
		<option value=<%=j%>>头像二</option>
		<option value=<%=k%>>头像三</option>
	</select></td>
	</tr>

    完成这些,就可以图片的路径传个servlet,servlet再存到数据库中,

相关推荐