切换案例简单示例不反映段落中的值

时间:2017-05-12 06:46:13

标签: javascript html

我在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;
&#13;
&#13;

3 个答案:

答案 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)

&#13;
&#13;
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;
&#13;
&#13;