<img src="code.png" onclick="this.src ={$maccms.path_tpl}picture/captcha.png"
这个不能使用js来做,js属于客户端脚本,手机验证码不能通过任何方式显示到前端,所以js不能来做校验实现方案是,点击获取验证码,发送手机号到服务端,服务端通过短信平台网关接口发送验证码;用户接收到验证码,输入验证码,然后将手机号和验证码同时提交到服务端,由服务端进行验证,并返回是否验证通过
整个过程中验证码并未出现在前端
<html><head>
<script language="javascript" type="text/javascript">
var code
function createCode(){
code = new Array()
var codeLength = 4
var checkCode = document.getElementById("checkCode")
checkCode.value = ""
var selectChar = new Array(2,3,4,5,6,7,8,9,'A','B','C','D','E','F','G','H','J','K','L','M','N','P','Q','R','S','T','U','V','W','X','Y','Z')
for(var i=0i<codeLengthi++) {
var charIndex = Math.floor(Math.random()*32)
code +=selectChar[charIndex]
}
checkCode.value = code
}
function validate () {
var inputCode = document.getElementById("yzm").value.toUpperCase()
if(inputCode != code ){
alert("验证码错误!")
return false
}
else {
alert("验证码正确!")
return true
}
}
</script>
<meta http-equiv="Content-Type" content="text/htmlcharset=gb2312">
</head>
<body onLoad="createCode()">
验证码:<input type="text" id="yzm" size="5" />
<input type="button" id="checkCode" onClick="createCode()" title="刷新验证码" style="width:50pxcolor:#F00border:0letter-spacing:1pxfont-family:Arial" />
<input type="button" id="Button1" onClick="validate()" value="确定" />
</body>
</html>