解决方案 »

  1.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <script type="text/javascript">
     function returnColor() {
                var str = "#";
                var arr = new Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f');
                for (var i = 0; i < 6; i++)
                {
                    str =str + arr[Math.floor(Math.random() * 16 + 1)];
                }
                str = str + "";
                alert(str);
                document.body.style.backgroundColor=str;
     };
     window.onload=returnColor;
    </script>
    </head><body>
    111
    </body>
    </html>
      

  2.   

            function returnColor() {
                var str = "#";
                for (var i = 0; i < 6; i++)
                {
                    str += Math.floor(Math.random() * 16 + 1).toString(16);
                }
                alert(str);
                $("#b1").css({ "background-color": str });
            };
      

  3.   

    楼上可以,不需要对\"转义,因为str本身就是个字符串
    转义过后就等同于$("#b1").css({ "background-color": "\"#FFF\"" });显然这是不对的