做了一个效果,不知道大家能不能用上

helei33 2002-12-24 01:16:01
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>New Page 1</title>
</head>
<script>
function selectOther(list) {
var input = document.createElement("INPUT");
input.className = "select";
input.type = "text";
input.onblur = function() {
var list = this.oldNode;
list.options[list.options.length - 1] = new Option(this.value, "", true);
list.options[list.options.length] = new Option("Other...");
list.selectedIndex = list.options.length - 2;

this.parentNode.replaceChild(list, this);
};
input.oldNode = list.parentNode.replaceChild(input, list);
}
</script>

<body>

<p><select size="1" name="D1">
<option>111</option>
<option>222</option>
<option>333</option>
</select><input type="submit" value="添加" name="B1" onclick=selectOther(D1)></p>
</body>
</html>
...全文
57 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
seabell 2002-12-24
  • 打赏
  • 举报
回复
like this?
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>New Page 1</title>
</head>
<script>
function selectOther(list) {
var input = document.createElement("INPUT");
input.className = "select";
input.type = "text";
input.onblur = function() {
var list = this.oldNode;
list.options[list.options.length - 1] = new Option(this.value, "", true);
list.options[list.options.length] = new Option("Other...");
list.selectedIndex = list.options.length - 2;

this.parentNode.replaceChild(list, this);
};
input.oldNode = list.parentNode.replaceChild(input, list);
}
</script>
<body>
<p><select size="1" name="D1" onchange="if(this.selectedIndex==this.options.length-1)selectOther(D1)">
<option>111</option>
<option>222</option>
<option>333</option>
<option>Other...</option>
</select>
</p>
</body>
</html>
helei33 2002-12-24
  • 打赏
  • 举报
回复
谢谢,如果大家有兴趣的话,可以修改修改,大家共享!
ssm1226 2002-12-24
  • 打赏
  • 举报
回复
OK
walkingpoison 2002-12-24
  • 打赏
  • 举报
回复
有点小问题,第一次会把原来的选项“333”覆盖掉,并且会多出来一项“Other..”,但是实际使用当中似乎这个Other选项没有什么作用。
hmbory 2002-12-24
  • 打赏
  • 举报
回复
改进一下就更不错:)
emu 2002-12-24
  • 打赏
  • 举报
回复
不错,还可以试试其他的做法,再接再厉啊!
seabell 2002-12-24
  • 打赏
  • 举报
回复
不错啊

87,923

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧