会员
周边
新闻
博问
闪存
赞助商
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
wendy's blog
Powered by
博客园
博客园
|
|
新随笔
|
|
|
管理
为Html 的Select 加一个提示语和输入方法
<!
DOCTYPE HTML PUBLIC
"
-//W3C//DTD HTML 4.0 Transitional//EN
"
>
<
html
>
<
head
>
<
title
></
title
>
<
meta name
=
"
GENERATOR
"
content
=
"
Microsoft Visual Studio .NET 7.1
"
>
<
meta name
=
ProgId content
=
VisualStudio.HTML
>
<
meta name
=
Originator content
=
"
Microsoft Visual Studio .NET 7.1
"
>
<
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
=
'
Z-INDEX:-1;WIDTH:130px
'
name
=
'
tmpSel
'
onmouseover
=
selMouseOver(
this
) onmouseout
=
selMouseOut(
this
) onkeydown
=
catch_keydown(
this
) onkeypress
=
catch_press(
this
) onfocus
=
catch_focus(
this
) ID
=
"
Select1
"
runat
=
"
server
"
>
<
option value
=
"
我
"
selected
>
cc
</
option
>
<
option value
=
"
aa
"
>
aa
</
option
>
<
option value
=
"
bb
"
>
bb
</
option
>
</
select
>
<!--
提示块
-->
<
div id
=
div_hint style
=
"
BORDER-RIGHT:#9c9c9c 1px solid;BORDER-TOP:#9c9c9c 1px solid;DISPLAY:none;FONT-SIZE:12px;FILTER:Alpha(style=0,opacity=80,finishOpacity=100);BORDER-LEFT:#9c9c9c 1px solid;COLOR:red;BORDER-BOTTOM:#9c9c9c 1px solid;BACKGROUND-COLOR:#f7f7f7;layer-background-color:#0099FF
"
></
div
><
FONT face
=
宋体
></
FONT
>
</
BODY
>
</
html
>
发表于
2004-12-27 19:54
快可天地
阅读(
1634
) 评论(
0
)
收藏
举报
刷新页面
返回顶部