JavaScript示例代码在Google Chrome中加载空白页

时间:2015-01-06 18:16:10

标签: javascript html

我无法在Google Chrome中正确加载此示例代码;它加载一个空白页面。代码似乎有什么问题?

代码如下:

<!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”>
    <body>
        <script type="text/javascript">
            var myString = “56.02 degrees centigrade”; 
            var myInt;
            var myFloat;

            document.write(“\“” + myString + “\“ is “ + parseInt(myString) + 
            “ as an integer” + “<BR>”);

            myInt = parseInt(myString);
            document.write(“\“” + myString + “\“ when converted to an integer equals “ +
            myInt + “<BR>”);

            myFloat = parseFloat(myString); document.write(“\“” + myString +
            “\“ when converted to a floating point number equals “ + myFloat);
        </script>
    </body>
</html>

1 个答案:

答案 0 :(得分:3)

戴夫是绝对正确的,这是引用。此版本带有固定引号,会在我的Chrome中加载。

<!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">
<body>

<script type="text/javascript">

var myString = "56.02 degrees centigrade"; 
var myInt;
var myFloat;

document.write("\"" + myString + "\" is " + parseInt(myString) + 
" as an integer" + "<BR>");

myInt = parseInt(myString);
document.write("\"" + myString + "\" when converted to an integer equals " +
myInt + "<BR>");

myFloat = parseFloat(myString); document.write("\"" + myString +
"\" when converted to a floating point number equals " + myFloat);

</script>

</body>
</html>

这就是我所看到的: enter image description here