我是新的JavaScript和在java腳本中使用相同的邏輯和邏輯運算符,但沒有得到正確的輸出,如果其他條件在JavaScript它給所有條件相同的輸出沒有得到正確的輸出,如果其他條件在Java腳本
<!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=iso-8859-1" />
<title>Untitled Document</title>
<script>
var x = document.getElementById["a"].value;
var y = document.getElementById["b"].value;
function compare()
{
if(x>y) {
alert ("x is greater");
} else if(x == y) {
alert ("both are equals");
} else {
alert("y is greater")
}
}
</script>
</head>
<body>
<form onsubmit="compare()" >
x---><input type="text" id="a"><br>
y---><input type="text" id="b"><br>
<input type="submit" name="submit" >
</form>
</body>
</html>
多個問題,以比較字符串(不是數字),以甚至創建輸入之前讀值。使用瀏覽器的開發人員工具。 – epascarello