指引网

当前位置: 主页 > 网页制作 > JavaScript >

js实现文本框中内容的放大显示

来源:网络 作者:佚名 点击: 时间:2017-08-07 22:13
[摘要] js实现文本框中内容的放大显示
js实现文本框中内容的放大显示

  1. <!doctype html> 
  2. <html> 
  3. <head> 
  4. <meta charset="utf-8"
  5. <title>文本框放大</title> 
  6. <script> 
  7. function $(id){ 
  8. return document.getElementById(id); 
  9.  
  10. function showBigInfo(obj){ 
  11. var bigObj; 
  12. if(!$("bigInfo")){ 
  13. bigObj=document.createElement("span"); 
  14. bigObj.setAttribute("id","bigInfo"); 
  15. bigObj.style.position="absolute"
  16. bigObj.style.border="1px solid #F93"
  17. bigObj.style.borderRadius="2px"
  18. bigObj.style.color="red"
  19. bigObj.style.fontSize="26px"
  20. bigObj.style.fontWeight="bold"
  21. bigObj.style.padding="4px"
  22. bigObj.style.display="none"
  23. document.body.appendChild(bigObj); 
  24. obj.onblur=function(){ 
  25. $("bigInfo").style.display="none"
  26. obj.onfocus=function(){ 
  27. $("bigInfo").style.display="block"
  28. }else
  29. bigObj=$("bigInfo"); 
  30. bigObj.style.display="block"
  31. var str=""
  32. var info=obj.value; 
  33. for(var i=0;i<info.length;i+=4){ 
  34. str+=info.substr(i,4)+" "
  35. bigObj.innerHTML=str;  
  36. if(obj.offsetTop<50){ //放大框在下方显示 
  37. bigObj.style.top=(obj.offsetTop+obj.offsetHeight+2)+"px"
  38. }else//放大框在上方显示 
  39. bigObj.style.top=(obj.offsetTop-bigObj.offsetHeight-2)+"px"
  40. bigObj.style.left=(obj.offsetLeft+obj.offsetWidth/2-bigObj.offsetWidth/2)+"px"
  41. </script> 
  42. </head> 
  43.  
  44. <body> 
  45. <br /><br /><br /><br /><br /><br /> 
  46. <center> 
  47.  
  48. 请输入身份证号码:<input type="password" onKeyUp="showBigInfo(this)" maxlength="18" size="30"/> 
  49. <br /> 
  50. 请输入身份证号码:<input type="password" onKeyUp="showBigInfo(this)" maxlength="18" size="30"/> 
  51. <br /> 
  52. 请输入身份证号码:<input type="password" onKeyUp="showBigInfo(this)" maxlength="18" size="30"/> 
  53.  
  54. </center> 
  55. </body> 
  56. </html> 

 

------分隔线----------------------------