gpt4 book ai didi

javascript 不在浏览器中生成,只是将代码打印到屏幕

转载 作者:行者123 更新时间:2023-11-30 09:09:26 27 4
gpt4 key购买 nike

首先,我没有要求任何人做我的家庭作业。这样做的目的是编写一个简单的网页来熟悉 javascript。它从名为“卡片”的文件夹中生成并显示随机卡片。我完成了那部分。然而,当我把它提交给老师时,他给我发回了这张截图,主题是“有什么想法吗?”

http://i38.tinypic.com/2wr3e2p.jpg

我已经在多台机器上测试过这个页面,它在每个浏览器中都可以正常工作。我不知道为什么它只是在他运行时将代码打印到页面上。有什么想法吗? (我假设他会启用 javascript,特别是因为我类的每个人都在提交这个程序)。

编辑:这是代码,抱歉,但我包含了所有内容只是为了清除任何问题

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Aaron's Gamble Page!</title>

<style type="text/css">
* { padding: 0; margin: 0; }

body
{
font-family: Arial, Helvetica, sans-serif;
font-size: 13px;
background: #48454C;
}
#wrapper
{
margin: 0 auto;
width: 365px;
}
#header
{
color: #333;
width: 365px;
padding: 10px;
margin: 10px 0px 0px 0px;
background: #A29EA2;
}
#centercolumn
{
color: #333;
padding: 10px;
width: 365px;
background: #DFE0DB;
}
#footer
{
width: 365px;
clear: both;
color: #333;
background: #A29EA2;
padding: 10px;
}
</style>

<script type="text/javascript" charset="utf-8">
// this page created by Aaron Albin
// creation date: October 17, 2009

var score = 0;

function generateCards()
{
var i, randType, randSuite;
var type = new Array("2", "3","4","5","6","7","8","9","t","j","q","k","a");
var suite = new Array("c","d","s", "h");
var cards = new Array(5);
for (i = 0; i < cards.length; i++)
{
cards[i] = setRandomCard(type, suite, cards);
document.write('<img src = "'+cards[i]+'">');
}
}

function setRandomCard(type, suite, cards)
{
var randType, randSuite;
var filePath = "file://C:/cards/";
var fileExt = ".gif";

do
{
randType = Math.floor(Math.random() * type.length);
randSuite = Math.floor(Math.random() * suite.length);
}
while(checkDuplicate(randType, randSuite, filePath, fileExt, type, suite, cards));

addScore(type, randType);
return filePath + type[randType] + suite[randSuite] + fileExt;
}

function checkDuplicate(randType, randSuite, filePath, fileExt, type, suite, cards)
{
var j;
for (j = 0; j < cards.length; j++)
{
if (cards[j] == filePath + type[randType] + suite[randSuite] + fileExt)
{
return true;
}
}
return false;
}

function addScore(type, randType)
{
switch(type[randType])
{
case "2":
score += 2;
break;
case "3":
score += 3;
break;
case "4":
score += 4;
break;
case "5":
score += 5;
break;
case "6":
score += 6;
break;
case "7":
score += 7;
break;
case "8":
score += 8;
break;
case "9":
score += 9;
break;
case "t":
score += 10;
break;
case "j":
score += 11;
break;
case "q":
score += 12;
break;
case "k":
score += 13;
break;
case "a":
score += 1;
break;
default:
score += 0;
}
}
</script>

</head>

<body>
<div id="wrapper">
<div id="header"></div>
<div id="centercolumn">
<h2>Gamble!</h2>
<br />
<p>Welcome to my gambling page. You have drawn</p><br />
<script type="text/javascript" charset="utf-8">generateCards();</script><br /><br />
<p>The value of this hand is <script type="text/javascript" charset="utf-8">document.write(score);</script>.</p>
<br />
</div>
<div id="footer"></div>
</div>
</body>
</html>

最佳答案

您确定您的代码列在权限标签内吗?

<script type="text/javascript" charset="utf-8">
// your code goes here
</script>

这是我唯一能想到的原因

关于javascript 不在浏览器中生成,只是将代码打印到屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1583279/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com