js实现img src更新请求


[javascript] view plain copy
  1. 1.javascript(更新的函数)
[javascript] view plain copy
[javascript] view plain copy
  1. <scripttype="text/javascript">
  2. functionchangeImage(){
  3. varimg=document.getElementById("imgVcode");
  4. if(img.name==1){
  5. img.name=2;
  6. img.src="shop.do?method=registerImage2";
  7. }elseif(img.name==2){
  8. img.name=1;
  9. img.src="shop.do?method=registerImage";
  10. }
  11. }
  12. </script>


2.jsp中img和img改变的代码

[plain] view plain copy
  1. <td>
  2. <imgclass="yzm_img"id='imgVcode'name="1"src="shop.do?method=registerImage"/>
  3. <inputname="code"type="text"id="txtVerifyCode"
  4. class="yzm_input"onblur="testCode(this)"/>
  5. <divclass="text_leftt1">
  6. <pclass="t1">
  7. <spanid="vcodeValidMsg">请输入图片中的四个字母。</span>
  8. <spanid="codeInfo"style="color:red"></span>
  9. <ahref="#"id="imgchange"onclick="changeImage()">看不清楚?换个图片</a>
  10. </p>
  11. </div>
  12. </td>


3.后台action代码

[java] view plain copy
  1. publicActionForwardregisterImage(ActionMappingmapping,ActionFormform,
  2. HttpServletRequestrequest,HttpServletResponseresponse)
  3. throwsException{
  4. //将image创建,返回认证码
  5. response.setContentType("image/jpeg");
  6. OutputStreamout=response.getOutputStream();
  7. StringstrEnsure=shopManager.createImageInfo(50,20,out);
  8. //设置到session中
  9. request.getSession().setAttribute("strEnsure",strEnsure);
  10. returnnull;
  11. }
  12. publicActionForwardregisterImage2(ActionMappingmapping,ActionFormform,
  13. HttpServletRequestrequest,HttpServletResponseresponse)
  14. throwsException{
  15. //将image创建,返回认证码
  16. response.setContentType("image/jpeg");
  17. OutputStreamout=response.getOutputStream();
  18. StringstrEnsure=shopManager.createImageInfo(50,20,out);
  19. //设置到session中
  20. request.getSession().setAttribute("strEnsure",strEnsure);
  21. returnnull;
  22. }
[javascript] view plain copy
  1. 1.javascript(更新的函数)
[javascript] view plain copy
[javascript] view plain copy
  1. <scripttype="text/javascript">
  2. functionchangeImage(){
  3. varimg=document.getElementById("imgVcode");
  4. if(img.name==1){
  5. img.name=2;
  6. img.src="shop.do?method=registerImage2";
  7. }elseif(img.name==2){
  8. img.name=1;
  9. img.src="shop.do?method=registerImage";
  10. }
  11. }
  12. </script>


2.jsp中img和img改变的代码

[plain] view plain copy
  1. <td>
  2. <imgclass="yzm_img"id='imgVcode'name="1"src="shop.do?method=registerImage"/>
  3. <inputname="code"type="text"id="txtVerifyCode"
  4. class="yzm_input"onblur="testCode(this)"/>
  5. <divclass="text_leftt1">
  6. <pclass="t1">
  7. <spanid="vcodeValidMsg">请输入图片中的四个字母。</span>
  8. <spanid="codeInfo"style="color:red"></span>
  9. <ahref="#"id="imgchange"onclick="changeImage()">看不清楚?换个图片</a>
  10. </p>
  11. </div>
  12. </td>


3.后台action代码

[java] view plain copy
  1. publicActionForwardregisterImage(ActionMappingmapping,ActionFormform,
  2. HttpServletRequestrequest,HttpServletResponseresponse)
  3. throwsException{
  4. //将image创建,返回认证码
  5. response.setContentType("image/jpeg");
  6. OutputStreamout=response.getOutputStream();
  7. StringstrEnsure=shopManager.createImageInfo(50,20,out);
  8. //设置到session中
  9. request.getSession().setAttribute("strEnsure",strEnsure);
  10. returnnull;
  11. }
  12. publicActionForwardregisterImage2(ActionMappingmapping,ActionFormform,
  13. HttpServletRequestrequest,HttpServletResponseresponse)
  14. throwsException{
  15. //将image创建,返回认证码
  16. response.setContentType("image/jpeg");
  17. OutputStreamout=response.getOutputStream();
  18. StringstrEnsure=shopManager.createImageInfo(50,20,out);
  19. //设置到session中
  20. request.getSession().setAttribute("strEnsure",strEnsure);
  21. returnnull;
  22. }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值