实现验证码需要前后端配合,这里后端使用 kaptcha,并直接使用img的src属性来添加:

<img src="/captcha" class="pull-left" id="captcha" style="cursor: pointer;" onclick="this.src=this.src+'?d='+Math.random();" title="点击刷新" alt="captcha">