紧急求助,在线,即时给分!!!

lilei22 2004-09-29 09:04:20
为什么下面这段代码执行后,只有第一次可以将val11变成下拉框,再变回来就不行了???
<%@ page contentType="text/html;charset=GB2312"%>
<SCRIPT Language="JavaScript">
function ChType(parts)
{
if (parts.value=="sex")
{
document.conditionForm.val12.options.length=0;
var opt=document.createElement("option");
opt.value="man";
opt.text="man";
document.all.val12.add(opt);
document.all.val11.outerHTML=ld.innerHTML;

}else{
document.all.val.value="df";
document.all.val11.outerHTML="<input type='text' name='val11' size='30' style='display'>";
}
}
</SCRIPT>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB2312">
<title>
Query condition
</title>
</head>
<body>
<h2>
Please Input Query Condition:
</h2>
<FORM action="" name="conditionForm">
<table cellspacing="2" cellpadding="1" border="1" width="429">
<tr>
<td width="125" align="center">数据字段</td>
<td width="65" align="center">操作符</td>
<td width="152">
<p align="center">取值</p>
</td>
<td width="64">
<p align="center">关系</p>
</td>
</tr>
<tr>
<td width="125"><select name="datatype1" onchange="ChType(this)">
<option value="name">姓名</option>
<option value="sex">性别</option>
<option value="ddd">ddd</option>
</select>
</td>
<td width="65">
<select name="oper1">
<option value="like" selected>类似</option>
<option value="=">等于</option>
<option value=">">大于</option>
<option value="<">小于</option>
</select>
</td>
<td width="152">
<input type='text' name='val11' size='30' style='display'>
<div id="ld" style="display:none">
<select name="val12" size="1" >
<option value="=">fdf</option>
</select>
</div>
</td>
<td width="64">
<select name="rel1">
<option value="and" selected>并且</option>
<option value="or">或者</option>
</select>
</td>
</tr>

</table>

</body>
</html>
...全文
105 7 打赏 收藏 举报
写回复
7 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
soonquick 2004-09-29
  • 打赏
  • 举报
回复
同意楼上。
<SCRIPT Language="JavaScript">
function ChType(parts)
{
document.all.val.value="eeee";
if (parts.value=="sex")
{
document.conditionForm.val11.value="eeee";
document.conditionForm.val12.options.length=0;
var opt=document.createElement("option");
opt.value="man";
opt.text="man";
document.all.val12.add(opt);
ld.style.display="";
aa.style.display="none";

}else{
document.all.val.value="df";
ld.style.display="none";
aa.style.display="";
}
}
</SCRIPT>

<div id="aa">
<input type='text' name='val11' size='30' style='display'>
</div>
<div id="ld" style="display:none">
<select name="val12" size="1" >
<option value="=">fdf</option>
</select>
</div>

lilei22 2004-09-29
  • 打赏
  • 举报
回复
请问如何实现这种功能比较好??
blestcc 2004-09-29
  • 打赏
  • 举报
回复
第一次替换成select时val11的内容已经被改变成了
<select name="val12" size="1" >
<option value="=">fdf</option>
</select>
val11就已经不存在了,可以把val11也改成一个div试试
lilei22 2004-09-29
  • 打赏
  • 举报
回复
重发完整代码如下:
<%@ page contentType="text/html;charset=GB2312"%>
<SCRIPT Language="JavaScript">
function ChType(parts)
{
document.all.val.value="eeee";
if (parts.value=="sex")
{
document.conditionForm.val11.value="eeee";
document.conditionForm.val12.options.length=0;
//var o=new option("男","man");
//document.all.val12.add(o);
//document.conditionForm.val12.options[document.conditionForm.val12.options.length]=new option("男","man");
//document.conditionForm.val12.options[document.conditionForm.val12.options.length]=new option("女","women");
var opt=document.createElement("option");
opt.value="man";
opt.text="man";
document.all.val12.add(opt);
document.all.val11.outerHTML=ld.innerHTML;

}else{
document.all.val.value="df";
document.all.val11.style="display:none";
//document.conditionForm.val11.options.length=0;
document.all.val11.innerHTML="<input type='text' name='val11' size='30' style='display'>";
// document.all.val11.outerHTML="";
//document.all.val11.value="df";
// var t = document.createElement("textfield");
//var tmp = document.getElementById('val11');
// tmp.style="display";
// tmp.size="4";
//tmp.parentNode.replaceChild(t,tmp);

}
}
</SCRIPT>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB2312">
<title>
Query condition
</title>
</head>
<body>
<h2>
Please Input Query Condition:
</h2>
<FORM action="" name="conditionForm">

<input type='text' name='val' size='30' style='display'>

<table cellspacing="2" cellpadding="1" border="1" width="429">
<tr>
<td width="125" align="center">数据字段</td>
<td width="65" align="center">操作符</td>
<td width="152">
<p align="center">取值</p>
</td>
<td width="64">
<p align="center">关系</p>
</td>
</tr>
<tr>
<td width="125"><select name="datatype1" onchange="ChType(this)">
<option value="name">姓名</option>
<option value="sex">性别</option>
<option value="ddd">ddd</option>
</select>
</td>
<td width="65">
<select name="oper1">
<option value="like" selected>类似</option>
<option value="=">等于</option>
<option value=">">大于</option>
<option value="<">小于</option>
</select>
</td>
<td width="152">
<input type='text' name='val11' size='30' style='display'>
<div id="ld" style="display:none">
<select name="val12" size="1" >
<option value="=">fdf</option>
</select>
</div>
</td>
<td width="64">
<select name="rel1">
<option value="and" selected>并且</option>
<option value="or">或者</option>
</select>
</td>
</tr>

</table>

</body>
</html>
lilei22 2004-09-29
  • 打赏
  • 举报
回复
我把val定义省去了,是一个文本框,问题不在这,而是后面的替换的问题
blestcc 2004-09-29
  • 打赏
  • 举报
回复
document.all.val.value="df";
对象不存在
zltostem 2004-09-29
  • 打赏
  • 举报
回复
document.all.val.value="df";



因为"val"没定义~~~
相关推荐
发帖
JavaScript

8.7w+

社区成员

Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
帖子事件
创建了帖子
2004-09-29 09:04
社区公告
暂无公告