我在javascript中有一个简单的switch case示例。但是,段落中的值应该反映为switch-case中的第三个选项,它没有显示任何内容或空白段落。 Pl,求助!
<html>
<head></head>
<body>
<p id="para1"></p>
<script>
var i = 3;
switch(i){
case 1: {
document.getElementById('para1').value = "The value is one.";
break;
}
case 2: {
document.getElementById('para1').value = "The value is two.";
break;
}
case 3: {
document.getElementById('para1').value = "The value is three.";
break;
}
default:{
document.getElementById('para1').value = "The value is undefined."
}
}
</script>
</body>
</html>
&#13;
答案 0 :(得分:2)
select top 1 ed.*, e.salary form Emp e INNER JOIN EmpDetail ed
ON e.ID=ed.ID
WHERE ed.City='Nagpur'
order by e.Salary desc
标记在p
元素中,因此它没有input
。您应该使用value
来设置值。
innerHTML
答案 1 :(得分:1)
使用innerHTML而不是value:
<html>
<head></head>
<body>
<p id="para1"></p>
<script>
var i = 3;
switch(i){
case 1: {
document.getElementById('para1').innerHTML = "The value is one.";
break;
}
case 2: {
document.getElementById('para1').innerHTML = "The value is two.";
break;
}
case 3: {
document.getElementById('para1').innerHTML = "The value is three.";
break;
}
default:{
document.getElementById('para1').innerHTML = "The value is undefined."
}
}
</script>
</body>
</html>
答案 2 :(得分:1)
var i = 3;
switch(i){
case 1: {
document.getElementById('para1').innerHTML = "The value is one.";
break;
}
case 2: {
document.getElementById('para1').innerHTML = "The value is two.";
break;
}
case 3: {
document.getElementById('para1').innerHTML = "The value is three.";
break;
}
default:{
document.getElementById('para1').innerHTML = "The value is undefined."
}
}
&#13;
<p id="para1">test</p>
&#13;