最近,我問關於JavaScript的編碼我的三角形的計算問題。基本上,我去的JSLint(一個JavaScript調試工具)來獲取一些數據,爲什麼沒有任何的功能和程序內部工作在那裏,因爲它所有的看起來不錯,我跟着前面給出的建議,但我相信這是另外一個問題。我發佈了以下代碼:使用Javascript - 在使用之前定義
<html>
<head>
<link href="stylesheet/stylesheet.css" rel="stylesheet" type="text/css">
<script language="Javascript" type="text/javascript">
/* Key/Legend
Var
inp1 = input1
inp2 = input2
inp3 = input3
Triangle_Inputs = Form Name
*/
/* Notes
In computing, a parser is one of the components in an interpreter or
compiler that checks for correct syntax and builds a data structure
(often some kind of parse tree, abstract syntax tree or other hierarchical structure)
implicit in the input tokens.
Technique
if (side1 is equal to side2 AND side 2 is equal to side3) {equalitateral}
if (side1 is equal to side2 AND side 2 doesn't equal to side3) {isosceles}
if (side1 doesn't equal to side2 AND side2 doesn't equal to side 3 AND side 3 doesn't equal side 1) {scalene}
http://www.w3schools.com/js/js_comparisons.asp
*/
function checkinputs(){
/* Var = parseInt(document.Name_Of_Element_Form.Field_Name(Input).value); */
/* Input Fields */
inp1 = parseInt(document.Triangle_Inputs.input1.value);
inp2 = parseInt(document.Triangle_Inputs.input2.value);
inp3 = parseInt(document.Triangle_Inputs.input3.value);
/* Side options */
sideA = (inp1);
sideB = (inp2);
sideC = (inp3);
if (sideA == sideB && sideB == sideC) {
alert("Equalateral");
}
if (sideA == sideB && != sideC) {
alert("Isosceles");
}
if (sideA != sideB == sideC) {
alert("Isosceles");
}
if (sideA != sideB != sideC != sideA) {
alert("Scalene!");
}
}
</script>
</head>
<body>
<div id="Container">
<div id="Header"><h1></h1></div>
<div id="Content_1">
<div id="Explanation">
This calculator will determine what
triangle you have made depending on
the integer values in the input fields.
</div>
<div id="Form">
<FORM NAME="Triangle_Inputs" METHOD="GET">
Enter the triangle values below: <br>
<p>
<h4>Side 1: </h4><BR>
<INPUT TYPE="Integer" NAME="input1" VALUE=""><P>
<h4>Side 2: </h4><BR>
<INPUT TYPE="Integer" NAME="input2" VALUE=""><P>
<h4>Side 3:</h4> <BR>
<INPUT TYPE="Integer" NAME="input3" VALUE=""><P>
<INPUT TYPE="button" NAME="Submit" Value="Submit" Class="Submit" onClick="checkinputs()">
</FORM>
</div>
<div id="Verbal_Output">
<h2>You made a:</h2>
<p>
<h2>Triangle</h2>
</div>
</div>
<p>
<p>
<div id="Content_2">
<div id="Image_Output">asdad</div>
</div>
</div>
</body>
</html>
這是網站本身,忽略div標籤。我想知道爲什麼我不能按一下按鈕多的點,爲什麼JSLint的說:
INP1 = parseInt函數(document.Triangle_Inputs.input1.value);它被定義之前使用
線39字符1「INP1」。
inp1,inp2和inp3。
編輯:
我使用變量的理解是不正確的,我把它們列出不使用「」 S。 相反,我打電話給一個變量,其餘的我不是。
你缺少'var'那就是爲什麼 – elclanrs
你好,你會不會詳細說明,會不會是 Var inp1 = integer; Var inp2 =整數; Var inp3 =整數; 謝謝:) –
是的,當你定義一個變量,把''變種之前,(小寫)。 – Abraham