========初始代码:
<div class="form-group">
<label for="inputvalidate" class="col-sm-3 control-label">验证码</label>
<div class="col-sm-4">
<input type="text" class="form-control" id="inputaccount" placeholder="请输入验证码">
</div>
<div class="col-sm-4">
<img id="loginform:vCode" src="validatecode.jsp" οnclick="javascript:document.getElementById('loginform:vCode'). src='validatecode.jsp?'+Math.random();" />
</div>
</div>
======修改后:注意加个随机数。唯一即可。比如 param=new Date()都行
<div class="col-sm-4">
<!-- js方式获取验证码===ok -->
<!-- <img id="loginform:vCode" src="validatecode.jsp" οnclick="javascript:document.getElementById('loginform:vCode'). src='validatecode.jsp?'+Math.random();" /> -->
<!-- juery方式获取验证码===ok -->
<img id="validatecode" src="validatecode.jsp" />
<!-- οnclick="validatecode();" -->
</div>
<script type="text/javascript">
/* function validatecode(){//jquery 事件
alert(Math.random());
$("#validatecode").attr("src","validatecode.jsp"+Math.random());
//$("#validatecode").attr("src","validatecode.jsp?param="+Math.random());
} */
$("#validatecode").click(function(){//jquery 事件
alert(Math.random());
//$("#validatecode").attr("src","validatecode.jsp"+Math.random());//地址栏有误
$("#validatecode").attr("src","validatecode.jsp?param="+Math.random());//==必须带参数名。否则请求url不对。404
} )
</script>