Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/370.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript函数未定义,但仍存在_Javascript_Function_Undefined Function - Fatal编程技术网

Javascript函数未定义,但仍存在

Javascript函数未定义,但仍存在,javascript,function,undefined-function,Javascript,Function,Undefined Function,我一整天都在做网站建设。因为我对Javascript/HTML还很陌生,所以我总是被卡住。今天我编写了这个文件,当我完成前两个javascript函数时,代码正常工作,但是当我完成第三个函数时,所有三个函数在控制台中都变得“未定义”。当我在浏览器中打开此文件时,它们不会执行任何操作。这是我的密码:` <html> <head> <title> Broker Page -- Stock Operating System </title> <li

我一整天都在做网站建设。因为我对Javascript/HTML还很陌生,所以我总是被卡住。今天我编写了这个文件,当我完成前两个javascript函数时,代码正常工作,但是当我完成第三个函数时,所有三个函数在控制台中都变得“未定义”。当我在浏览器中打开此文件时,它们不会执行任何操作。这是我的密码:`

<html>
<head>
<title> Broker Page -- Stock Operating System </title>
<link rel="stylesheet" type="text/css" href="styleSheet.css" />
<h1> Welcome to Broker Page! </h1>

<script type="text/javascript"> 
function executeStock() {
     var stockPrice = Math.random() * 10;
     var inputStr = document.getElementById('stockName').value;
     if (inputStr != "") {
         if (inputStr.length != 6)
             alert('Please enter 6 digits for the stock ID!');
         else if (inputStr >= 0)
             document.write("The stock price for the stock you are searching for is " + stockPrice.toPrecision(2));
         else 
             document.write("<h1> <font face="Calibri"> The stock ID you entered is invalid! It must only contain digits! </font> </h1>");
     }
}

function buyStock() {
     var stockID = document.getElementById('buyingStock').value;
     var stockShares = document.getElementById('stockShare').value;
     if (stockID.length != 6) {
          alert("The stock ID you entered must be six digits!");
          return;
     }
     if (stockShares > 0) {
          alert("You succeeded!");
     } else 
          document.write("<h1>The stock share you entered is invalid. Please try again!</h1>");
}

function sellStock() {
     var stockIDToSell = document.getElementById('sellOne').value;
     var sellSh = document.getElementById('sellShare').value;
     if (stockIDToSell.length != 6) {
          alert("The stock ID you entered must be six digits!");
          return;
     }
     if (sellSh > 0) {
          alert("You sold " + sellSh + " share of stock with ID: " + stockIDToSell);
     } else 
          document.write("<h1>The stock share you entered is invalid. Please try again!</h1>");
}

</script>

</head>
<body>
<div align="center">
<form method="post" onsubmit="executeStock();" >
<font face="Calibri" color=#880000> Search Stock </font>
<input type="text" id="stockName" size="13" />
<input type="submit" id="SubmitSearch" value="go" style="width:40px;height:30px;font-size:16" />
</form>
</div>
<br> </br> 
<div align="center">
<form method="post" onsubmit='buyStock();'>
<font face="Calibri" color=#880000 size=12> Buy Stocks </font> <br> </br>
<font face="calibri" color=#000000> Enter the stock ID: </font>
<input type="text" value="" id="buyingStock" />
<br> </br> 
<font face="calibri" color=#880000> Enter share: </font>
<input type="text" value="" id="stockShare" />
<input type="submit" value="Buy!" />

</form>

<form method="post" onsubmit='sellStock();'>
<font face="Calibri" color=#008800 size=12> Sell Stocks </font> 
<br> </br>
<font face="calibri" color=#000000> Enter the stock ID: </font>
<input type="text" value="" id="sellOne" />
<br> </br> 
<font face="calibri" color=#880000> Enter share: </font>
<input type="text" value="" id="sellShare" />
<input type="submit" value="Sell!" />

</form>

</div>
<div align="center">
<p> <font face="Calibri"> Your client information and recent transactions will be loaded here. </font> </p>
</div>

</body>
</html>

经纪人页面--股票操作系统
欢迎来到经纪人页面!
函数executeStock(){
var stockPrice=Math.random()*10;
var inputStr=document.getElementById('stockName')。值;
如果(inputStr!=“”){
如果(inputStr.length!=6)
警报('请为股票ID输入6位数字!');
否则如果(inputStr>=0)
document.write(“您正在搜索的股票的股价为”+stockPrice.toPrecision(2));
其他的
document.write(“您输入的股票ID无效!它只能包含数字!”);
}
}
函数buyStock(){
var stockID=document.getElementById('buyingStock')。值;
var stockShares=document.getElementById('stockShares')。值;
如果(stockID.length!=6){
警报(“您输入的股票ID必须是六位数字!”);
返回;
}
如果(股票>0){
警惕(“你成功了!”);
}否则
document.write(“您输入的股票份额无效,请重试!”);
}
函数sellStock(){
var stockIDToSell=document.getElementById('sellOne').value;
var sellSh=document.getElementById('sellShare').value;
if(stockIDToSell.length!=6){
警报(“您输入的股票ID必须是六位数字!”);
返回;
}
如果(sellSh>0){
警报(“您出售了”+sellSh+”股票,股票ID为“+stockIDToSell”);
}否则
document.write(“您输入的股票份额无效,请重试!”);
}
搜索股票


买股票

输入股票ID:

输入共享: 卖出股票

输入股票ID:

输入共享: 您的客户信息和最近的交易将在此处加载


`有人能帮我解决这个问题吗?这绝对不是一个重复的问题。谢谢。

第18行似乎有语法错误:

         document.write("<h1> <font face="Calibri"> The stock ID you entered is invalid! It must only contain digits! </font> </h1>");
document.write(“您输入的股票ID无效!它只能包含数字!”);
“face”属性的双引号干扰了用于document.write()调用的引号。要解决此问题,可以对document.write()调用使用单引号,或在“face”属性中转义双引号:

         document.write('<h1> <font face="Calibri"> The stock ID you entered is invalid! It must only contain digits! </font> </h1>');
document.write('您输入的股票ID无效!它只能包含数字!');

document.write(“您输入的股票ID无效!它只能包含数字!”);

您不应该使用
文档。write
,使用insteadit是因为文档。write()-如果在文档准备就绪后调用它,它将替换文档开始使用开发工具或firebug。如果没有调试器,即使您精通javascript,也很难找出原因。face=“Calibri”出错。可能重复
 document.write("<h1> <font face=\"Calibri\"> The stock ID you entered is invalid! It must only contain digits! </font> </h1>");