小弟最近写了一段代码,如下.起初,页面默认显示的是DIV CON1里的内容,当选择了下拉框里的值时,页面显示查询结并隐去DIV CON1的内容.现在是不管有没有选择下拉框,都是显示DIV CON1.现请教个位大侠是哪里错了,应该如何写?谢谢!
<!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=gb2312" />
<title>标签轮换</title>
<script type="text/javascript">
var t = document.getElementById("select_con");
alert(t.options[t.selectedIndex].value);
{
if (t.options[t.selectedIndex].value != 0);
document.getElementById("con2").style.display="block";
}
</script>
</head><body>
<div id="top">
<select name="pr" id="select_con">
<option value="0">请选择城市</option>
<option value="1">广州</option>
<option value="2">深圳</option>
<option value="3">东莞</option>
</select>
</div>
<div id="con1"><h2>中华人民共和国</h2></div>
<div style="display:none" id="con2"><p>显示查询结果</p></div>
</body>
</html>
<!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=gb2312" />
<title>标签轮换</title>
<script type="text/javascript">
var t = document.getElementById("select_con");
alert(t.options[t.selectedIndex].value);
{
if (t.options[t.selectedIndex].value != 0);
document.getElementById("con2").style.display="block";
}
</script>
</head><body>
<div id="top">
<select name="pr" id="select_con">
<option value="0">请选择城市</option>
<option value="1">广州</option>
<option value="2">深圳</option>
<option value="3">东莞</option>
</select>
</div>
<div id="con1"><h2>中华人民共和国</h2></div>
<div style="display:none" id="con2"><p>显示查询结果</p></div>
</body>
</html>
解决方案 »
- [jquery]请问下面代码如何改成通用一点的或者写一个插件
- 我的项目中有多个js文件,能不能这样做?
- showModalDialog怎么取不到中文参数?
- 用js能作出 如何实现45度的游戏地图
- 怎样在firefox中实现showModalDialog的功能?
- 关于变量的简单问题!
- 我想让<td>中的文字都变个颜色。在html中应该怎么做到啊。
- 求"Lostinet的JScript函数库"的注解
- 如何实现Shift+Click事件
- 请教如保用javascript把一串字符串加到 一个类似textList的下拉列表中
- 图片提交前预览 请高手指点
- height: auto; 与不写height 有什么区别啊
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>标签轮换 </title>
<script type="text/javascript">
window.onload=function() {
var t = document.getElementById("select_con");
t.onchange=function()
{
if (t.options[t.selectedIndex].value != 0)
document.getElementById("con2").style.display="block";
else
document.getElementById("con2").style.display="none";
}
}
</script>
</head> <body>
<div id="top">
<select name="pr" id="select_con">
<option value="0">请选择城市 </option>
<option value="1">广州 </option>
<option value="2">深圳 </option>
<option value="3">东莞 </option>
</select>
</div>
<div id="con1"> <h2>中华人民共和国 </h2> </div>
<div style="display:none" id="con2"> <p>显示查询结果 </p> </div>
</body>
</html>
var t = document.getElementById("select_con");
t.onchange = function() {
{
if (t.options[t.selectedIndex].value != 0){
document.getElementById("con2").style.display="block";
document.getElementById("con2").innerHTML="<p>"+t.options[t.selectedIndex].text+"</p>";
document.getElementById("con1").style.display="none";
} else {
document.getElementById("con1").style.display="block";
document.getElementById("con2").style.display="none";
}
}
}
}
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>标签轮换 </title>
<script type="text/javascript">
function sChange(t){
if (t.options[t.selectedIndex].value != 0)
document.getElementById("con2").style.display="block";
else
document.getElementById("con2").style.display="none";
}
</script>
</head> <body>
<div id="top">
<select name="pr" id="select_con" onchange=sChange(this)>
<option value="0">请选择城市 </option>
<option value="1">广州 </option>
<option value="2">深圳 </option>
<option value="3">东莞 </option>
</select>
</div>
<div id="con1"> <h2>中华人民共和国 </h2> </div>
<div style="display:none" id="con2"> <p>显示查询结果 </p> </div> </body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>标签轮换 </title>
<script type="text/javascript">
function change() {
var t = document.getElementById("select_con");
t.onchange=function()
{
if (t.options[t.selectedIndex].value != 0)
document.getElementById("con2").style.display="block";
else
document.getElementById("con2").style.display="none";
}
}</script>
</head> <body>
<div id="top">
<select name="pr" id="select_con" OnChange="change()">
<option value="0">请选择城市 </option>
<option value="1">广州 </option>
<option value="2">深圳 </option>
<option value="3">东莞 </option>
</select>
</div>
<div id="con1"> <h2>中华人民共和国 </h2> </div>
<div style="display:none" id="con2"> <p>显示查询结果 </p> </div>
</body>
</html>