火狐、傲游、猎豹、chrome不兼容document.all

http://rebecca.iteye.com/blog/1173548

http://hi.baidu.com/sxjlvwj/item/d45bf2905956810e924f41b2

 

火狐不支持.innerText(其他浏览器支持但是不支持.all)

View Code
 1 <script type="text/javascript">

 2     function validateCode() {

 3         var validatevalue = "";

 4         var codes = new Array(4);

 5         var colors = new Array("Red", "Green", "Gray", "Blue", "Maroon", "Aqua", "Fuchsia", "Lime", "Olive", "Silver");

 6         for (var i = 0; i < codes.length; i++) {

 7             codes[i] = Math.floor(Math.random() * 10);

 8             validatevalue += codes[i];

 9         }

10         var spans = document.getElementById("divCode").getElementsByTagName("*");

11         //var spans = document.getElementById("divCode").all;

12         for (var i = 0; i < spans.length; i++) {

13             spans[i].innerText = codes[i];

14             spans[i].style.color = colors[Math.floor(Math.random() * 10)];

15         }

16         document.getElementById("validatevalue").value = validatevalue;

17     }

18 

19     function validate() {

20         if (document.getElementById("textfield3").value != document.getElementById("validatevalue").value) {

21             alert("验证码错误");

22             validateCode();

23             document.getElementById("textfield3").value = "";

24             document.getElementById("textfield3").focus();

25             return false;

26         } else {

27             return true;

28         }

29     }

30     document.onload = validateCode();

31 </script>

 

http://www.cnblogs.com/haimingpro/archive/2012/09/06/2673270.html

 

你可能感兴趣的:(document)