JS代码:保存在js文件中
       function keycode() {
            var codeImg = $("#IMG1");
            var img2 = $("#img2");
            var codeTxt = $("#txtCode");
            var TextXY = codeTxt.offset(); //, "display": "block"
            var textWidth = codeTxt.width() + 10;
            codeImg.css({ "width": "120px", "height": "40px" })
            .click(function() {
                $(this).attr("src", "CheckCode.aspx?s=" + Math.random());
                codeTxt.focus();
            });
            codeTxt.focus(function() {
                codeImg.css({ "z-Index": "9999", "position": "absolute", "left": TextXY.left + textWidth, "top": TextXY.top + 2 }).fadeIn("slow");
            }).blur(function() { codeImg.fadeOut("slow"); });
            img2.click(function() {
                codeImg.attr("src", "CheckCode.aspx?s=" + Math.random());
                codeTxt.focus();
            });
            img2.css({ "text-decoration": "underline", "margin-left": "4px" })
             .mouseover(function() { $(this).css("cursor", "pointer"); });
        }
ASPX页面中
<script type="text/javascript"> 
        $(function() {
            //txtcheckcode
            keycode();
        });
 
    </script> <img id="IMG1" src="CheckCode.aspx" style="display: none;" />
    <input type="text" id="txtCode" /><span style="color:Red;font-size:9pt;" id="img2">点击刷新</span>也可以到http://mba.szu.edu.cn/exp 中查看IE8里不显示,但在兼容模式下显示
FF,GOOGLE,APPLE,IE7,IE6,OPERA正常显示