会员
商店
众包
新闻
博问
闪存
赞助商
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
Lengzihaohong
学无止境(专注于DotNet技术)
随笔 - 44, 文章 - 1, 评论 - 0, 阅读 -
29200
博客园
::
首页
::
新随笔
::
联系
::
订阅
::
管理
<
2025年3月
>
日
一
二
三
四
五
六
23
24
25
26
27
28
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
5
公告
记录项目开发过程中的点滴,总结技术要点,珍藏网络技术文章-----神话
昵称:
神话
园龄:
18年11个月
粉丝:
0
关注:
0
搜索
常用链接
我的随笔
我的评论
我的参与
最新评论
我的标签
更多链接
随笔分类
Ajax.net(2)
Asp.net(C#)(13)
Javascript(7)
控件开发(9)
数据库(3)
网页小代码(收藏)(6)
项目开发(4)
随笔档案
2007年9月(1)
2007年8月(3)
2007年7月(1)
2007年6月(9)
2007年5月(2)
2007年3月(28)
文章档案
2007年3月(1)
博客网站
DotNet男孩社区
博客堂
邹建的博客
《孟宪会之精彩世界》之.NET开发者园地
友情博客链接
Blog
维生素C.net
武眉博<活靶子.Net>
OOP80
tonyqus
CZoneSoft
四叶草
i am myself
一帆(老鼠粮仓之路)
随风.NET点滴
今夜太冷
鸟食轩
听棠.NET
男人.年久失羞
mill2002
dudu
DooIT
冰戈
清清月儿
更多
阅读排行榜
1. 初次使用ZedGraph(2253)
2. 梅花雪日历控件(网络收藏)(2126)
3. 获取某行的字段ID值(GridView模板列) (1995)
4. C#的float型,竟然与SQL中float型不对应(转载)(1972)
5. 动态SQL语法及获取本周、本月、本年时间段值(1925)
6. 移除Flash边框(1831)
7. 生成html页面(1615)
8. ListBox控件上移、下移操作(Ajax)(1382)
9. javascript动态增加、删除、填充表格内容(1009)
10. 文本框回车时触发按钮事件(用户控件ascx)(875)
为Html 的Select 加一个提示语和输入方法(转载)
Posted on
2007-08-28 10:22
神话
阅读(
353
) 评论(
0
)
编辑
收藏
举报
为Html 的Select 加一个提示语和输入方法(转载)
<
Html
>
<
Head
>
<
SCRIPT
LANGUAGE
="JavaScript"
>
<!--
//
定义 select 原值
var
oldValue,oldText;
//
select下拉框的onkeydown事件,修改下拉框的值
function
catch_keydown(sel)
{
switch
(event.keyCode)
{
case
13
:
//
回车键
event.returnValue
=
false
;
break
;
case
27
:
//
Esc键
sel.options[sel.selectedIndex].text
=
oldText;
sel.options[sel.selectedIndex].value
=
oldValue;
event.returnValue
=
false
;
break
;
case
8
:
//
空格健
var
s
=
sel.options[sel.selectedIndex].text;
s
=
s.substr(
0
,s.length
-
1
);
if
(sel.options[sel.selectedIndex].value
==
sel.options[sel.selectedIndex].text)
{
sel.options[sel.selectedIndex].value
=
s;
sel.options[sel.selectedIndex].text
=
s;
}
event.returnValue
=
false
;
break
;
}
if
(
!
event.returnValue
&&
sel.onchange)
sel.onchange(sel)
}
//
select下拉框的onkeypress事件,修改下拉框的值
function
catch_press(sel)
{
if
(sel.selectedIndex
>=
0
)
{
var
s
=
sel.options[sel.selectedIndex].text
+
String.fromCharCode(event.keyCode);
if
(sel.options[sel.selectedIndex].value
==
sel.options[sel.selectedIndex].text)
{
sel.options[sel.selectedIndex].value
=
s;
sel.options[sel.selectedIndex].text
=
s;
}
event.returnValue
=
false
;
if
(
!
event.returnValue
&&
sel.onchange)
sel.onchange(sel)
}
}
//
select下拉框的onfocus事件,保存下拉框原来的值
function
catch_focus(sel)
{
oldText
=
sel.options[sel.selectedIndex].value;
oldValue
=
sel.options[sel.selectedIndex].value;
}
//
恢复select下拉列表当前选中的值
function
LoadSelect(obj,value)
{
for
(
var
i
=
0
; i
<
obj.options.length; i
++
)
if
(obj.options[i].value
==
value)
{
obj.selectedIndex
=
i;
break
;
}
}
//
select 选择框鼠标上移时提示选择的内容
function
selMouseOver(obj)
{
with
(document.all.div_hint)
{
innerText
=
obj.options[obj.selectedIndex].text;
if
(innerText.length
>
0
)
{
innerText
=
"
"
+
innerText
+
"
"
;
style.display
=
"
block
"
;
style.left
=
event.clientX
+
16
;
style.top
=
event.clientY;
}
}
}
//
select 选择框鼠标移开时消失
function
selMouseOut(obj)
{
with
(document.all.div_hint)
{
style.display
=
"
none
"
}
}
//
-->
</
SCRIPT
>
</
Head
>
<
Body
>
<!--
调用
-->
<
select
style
='width:130px;z-index:-1'
name
='tmpSel'
onmouseover
=selMouseOver(this)
onmouseout
=selMouseOut(this)
onkeydown
=catch_keydown(this)
onkeypress
=catch_press(this)
onfocus
=catch_focus(this)
>
<
option
value
=''
></
option
>
</
select
>
<!--
提示块
-->
<
div
id
=div_hint
style
="font-size:12px;color:red;display:none;position:absolute; z-index:2; top:200;background-color: #F7F7F7; layer-background-color: #0099FF; border: 1px #9c9c9c solid;filter:Alpha(style=0,opacity=80,finishOpacity=100);"
></
div
>
</
Body
>
</
Html
>
刷新页面
返回顶部
(评论功能已被禁用)
【推荐】100%开源!大型工业跨平台软件C++源码提供,建模,组态!
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
Powered by:
博客园
Copyright © 2025 神话
Powered by .NET 9.0 on Kubernetes
点击右上角即可分享
AI原生IDE
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步