-5
目前我正在處理我的第一個Javascript HTML應用程序。現在我想介紹一下if語句。但是,這不起作用。有人可以向我解釋我做錯了什麼,我該如何解決這個問題?如果語句沒有捕獲NaN
提前感謝
<html>
<style type="text/css">
label {
text-align: left;
width: 200px;
display: block;
float: left;
clear: left;
margin-right: 3px;
cursor: pointer;
font: normal 16px ventura;
color: white
}
.button{
width: 95px;
font: normal 16px ventura;
margin-right: 3px;
margin-bottom: 3px;
}
.print{
width: 350px;
height: 200px;
var x = document.getElementById("Vectorlength").value;
document.getElementById("demo").innerHTML = x;
}
</style>
<body bgcolor= "#119ed8">
<form id="form1">
<p><label for="Vectorlength">Vector length (bp):</label>
<input type="text" name="Vectorlength" value="" />
</p>
<p><label for="Vectormass">Vector mass (ng):</label>
<input type="text" name="Vectormass" value="" />
</p>
<p><label for="Vectorconcentration">Vector concentration (ng/µL):</label>
<input type="text" name="Vectorconcentration" value="" />
</p>
<p><label for="Insertlength">Insert length (bp):</label>
<input type="text" name="Insertlength" value="" />
</p>
<p><label for="Insertconcentration ">Insert concentration (ng/µL):</label>
<input type="text" name="Insertconcentration" value="" />
</p>
<p><label for="Ratio">Ratio Insert/Vector:</label>
<input type="text" name="Ratio" value="3" />
</p>
</form>
<button onclick="outputname()">Submit</button>
<script>
function outputname() {
var x,y,name,a,b,answer, L,M;
x=document.getElementById("form1") ;
L=x.elements["Vectorlength"].value;
M=x.elements["Vectormass"].value;
C=x.elements["Vectorconcentration"].value;
iL=x.elements["Insertlength"].value;
iC=x.elements["Insertconcentration"].value;
R=x.elements["Ratio"].value;
y=Number(L)+Number(M);
if (y==NaN)
document.getElementById("demo").innerHTML+=" is not valid! <br>";
else
document.getElementById("demo").innerHTML=+y+"<br>";
}
</script>
<p id="demo"></p>
</body>
</html>
這是JavaScript而不是java – Jens
我已將[tag:java]標籤更改爲[tag:javascript]標籤。請理解,這是兩種完全不同的編程語言,與漢堡一樣緊密相關,如果你錯誤地標記了你的問題,你將不會得到正確的專家來檢查它,並且這可能會傷害你獲得漢堡的機會體面的幫助。由於我對JavaScript一無所知,這就是我能爲你做的所有事情,除非希望你很好,並希望你很快得到一個體面的答案。 –
您的CSS中有一段JavaScript語句...?! –