在程序中,我试图接受用户的拒绝并在标签上显示不是正面或负面 如何指定标签?
<html>
<Head>
<title> If Else Demo Program</title>
<style>
thead {color:green;}
tbody {color:green;}
tfoot {color:red;}
table{
border: 1px solid black;
border-color:red;
}
#No1{
background-color:lightyellow;
}
tr{
border:1px solid black;
border-color:pink;
}
td{
border:1px solid black;
border-color:gray;
}
</style>
</Head>
<body>
<table>
<thead>
<tr>
<td>Enter a no</td>
<td><input type="text" name="No1" id="No1"><br></td>
</tr>
</thead>
<tbody>
<tr>
<td>
<h3>Body section with green color</h3>
</td>
<td><label for="Output" name="lblMessage" id="Message">output</label> </td>
</tr>
</tbody>
<tr>
<tbody>
<td>
<input type="Submit" onclick="Demo()">
</td>
</tbody>
</tr>
</table>
<script type="Text/JavaScript" lang="JavaScript">
function Demo()
{
var No1=parseInt(document.getElementById("No1").value);
if(No1>0)
document.getElementById("Message").InnerHTML=("Positve No ",No1);
else
document.getElementById("Message").InnerHTML=("Negative No ",No1);
}
</script>
</body>
</html>
答案 0 :(得分:1)
你有一个小的语法错误,InnerHTML实际上应该是innerHTML。也是一个重构建议。
function Demo() {
var No1 = parseInt(document.getElementById("No1").value);
var Message = document.getElementById("Message");
if ( No1 > 0 ) {
Message.innerHTML = "Positive number " + No1;
} else {
Message.innerHTML = "Negative number " + No1;
}
}
答案 1 :(得分:0)
if(num1>0)
document.getElementById("message").innerHTML=("Positve No " + num1);
else
document.getElementById("message").innerHTML=("Negative No "+ num1);
InnerHTML
应为innerHTML
并使用+
组合两个值。