页面代码:
<div class="formControls col-8 col-offset-3"> <input class="input-text size-L" name="verfiy" type="text" placeholder="验证码" onblur="if(this.value==''){this.value='验证码:'}" onclick="if(this.value=='验证码:'){this.value='';}" value="验证码:" style="width:150px;"> <img src="<{:U('Login/verfiy')}>"><a id="code" href="javascript:;">看不清,换一张</a> </div> </div>
JQ代码:
<script type="text/javascript"> //点击刷新 $("#code").on("click", function () { $(this).prev().attr("src","<{:U(MODULE_NAME .'/Login/verfiy')}>/" + Math.random()); }) //获取焦点 验证刷新 $("input[name=verfiy]").focus(function () { $("#code").trigger('click'); }); </script>