main.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. function initInputs() {
  2. var _inputs = document.getElementsByTagName('input');
  3. if (_inputs) {
  4. for(var i=0; i<_inputs.length; i++) {
  5. if (_inputs[i].type == 'text' || _inputs[i].type == 'password') {
  6. _inputs[i].alt = _inputs[i].value;
  7. (function(i){
  8. var _hasFocus = false;
  9. _inputs[i].onmouseover = function(){
  10. if(this.className.indexOf('hover')<0)
  11. this.className += ' hover';
  12. }
  13. _inputs[i].onmouseout = function(){
  14. if(!_hasFocus)
  15. this.className = this.className.replace('hover','');
  16. }
  17. _inputs[i].onfocus = function(){
  18. if(this.className.indexOf('hover')<0)
  19. this.className += ' hover';
  20. _hasFocus = true;
  21. }
  22. _inputs[i].onblur = function(){
  23. this.className = this.className.replace('hover','');
  24. _hasFocus = false;
  25. }
  26. })(i);
  27. }
  28. }
  29. }
  30. }
  31. if (window.addEventListener)
  32. window.addEventListener("load", initInputs, false);
  33. else if (window.attachEvent)
  34. window.attachEvent("onload", initInputs);