这样试试
function $(id){
return document.getElementById(id);
}
var slt=$("city");
slt.onchange = function(){
if(this.value==''){
$('othercity').style.display="";
}
else{
$('othercity').style.display="";
$('othercity').value="";
}
}
function $(id){
return document.getElementById(id);
}
var slt=$("city");
slt.onchange = function(){
if(this.value==''){
$('othercity').style.display="";
}
else{
$('othercity').style.display="";
$('othercity').value="";
}
}
解决方案 »
- javascript
- 光盘中的html文件,如何用JavaScript或vbscript获取光盘所在光驱的盘符?
- 加载json.js提示JSON未定义,行199
- 想好好学习javascript,各位大大介绍一下学习路线
- JS 调用问题
- 求助javascript怎样读取数据库中的数据!
- 用showModalDialog打开的页面,点击页面里的链接会新开一个窗口,有什么办法不新开窗口,就在showModalDialog页面里
- onDragStart|onSelectStart的问题
- 请问如何控制复选框不能选择?
- js中relpace与直接赋值的区别
- javascript选项卡特效
- javascript键盘事件适用范围问题...谢谢
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
</HEAD>
<script type="text/javascript">
function $(id){
return document.getElementById(id);
}
var change=function(){
for(var i=0;i<$("city").options.length;i++){
if($("city").value==""){
$('othercity').style.display="block";
}else {
$('othercity').style.display="none";
$('othercity').value="";
}
}
}</script>
<BODY>
<dt>所在城市:</dt>
<select name='city' onchange="change()" id='city'>
<option value='Bath'>Bath</option>
<option value='Cambridge'>Cambridge</option>
<option value='Leeds'>Leeds</option>
<option value="">其他</option>
</select>
<input id='othercity' type='text' style="display:none;"/>
</BODY>
</HTML>
if (slt.options[slt.selectedIndex].value == "") {
getValue('othercity').style.display="block";
getValue('othercity').value = "";
} else {
getValue('othercity').style.display="none";
}