首先定义存放验证码的标签
<span id="ShowSheckcode"></span><span><a href="#" οnclick="checkcode()">换一张</a></span>
定义脚本为了保证后退页面也能刷新验证码,专门加了一个随机数
<script type="text/javascript" >
$(function () {
checkcode();
});
function checkcode() {
var str="<img src= 'RandomImage.aspx?"+ Math.random()+ " ' style='width:55px; height:20px;vertical-align:middle ' border='0' /> ";
$('#ShowSheckcode').html(str);
// document.write("<img src= 'RandomImage.aspx?", Math.random(), " ' style='width:55px; height:20px;vertical-align:middle ' border='0' /> ")
}
</script>
参考来自: http://topic.csdn.net/t/20060209/17/4547848.html
<script> document.write( " <img src= 'http://verify.qq.com/getimage? ",Math.random(), " '> ") </script>