zoukankan
html css js c++ java
可选择也可填写的下拉框(用鼠标\键盘的上下键选择)
<!
DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
>
<
html
>
<
head
>
<
title
>
Untitled
</
title
>
<
script
language
='javascript'
>
function
getstring()
{
return
"
<input id=\
"
key\
"
type=text ondblclick=\
"
showMenu()\
"
onkeydown=\
"
selectElement()\
"
value=\
"
请用鼠标双击击这里\
"
/>
"
;
}
function
getKeyCode()
{
//
alert(window.event.keyCode);
//
alert(document.getElementById("key").value);
document.getElementById(
"
key
"
).value
+=
window.event.keyCode;
}
//
==========================================================================================================
function
mouseOver(e)
{
e.style.background
=
"
#0080ff
"
;
}
function
mouseOut(e)
{
e.style.background
=
"
#ff8000
"
;
}
function
mouseClick(e)
{
document.getElementById(
"
key
"
).value
=
e.innerText;
e.parentNode.style.display
=
"
none
"
;
}
var
num
=
0
;
var
divObj;
function
showMenu()
{
var
arr
=
getOjbPosition();
var
left
=
arr[
0
];
var
top
=
arr[
1
];
//
alert(left+" : "+top);
var
obj
=
document.getElementById(
"
key
"
);
var
div
=
document.getElementById(
"
Menu
"
);
div.style.position
=
"
absolute
"
;
div.style.background
=
"
#ff8000
"
;
div.style.zIndex
=
2000
;
div.style.left
=
left;
div.style.top
=
top;
div.style.width
=
obj.offsetWidth;
div.style.display
=
""
;
divObj
=
div;
num
=
div.childNodes.length;
}
function
getDiv()
{
var
div
=
document.getElementById(
"
Menu
"
);
var
num
=
div.childNodes.length;
for
(
var
i
=
0
;i
<
num;i
++
)
{
alert(div.childNodes[i].outerHTML);
div.childNodes[i].style.background
=
"
#0080ff
"
;
}
}
function
getOjbPosition()
{
var
arr
=
new
Array();
var
obj
=
document.getElementById(
"
key
"
);
var
x
=
obj.offsetLeft;
var
y
=
obj.offsetTop
+
obj.offsetHeight;
while
(obj.offsetParent)
{
obj
=
obj.offsetParent;
x
+=
obj.offsetLeft;
y
+=
obj.offsetTop;
}
arr[
0
]
=
x;
arr[
1
]
=
y;
return
arr;
}
var
k
=
0
;
var
tag
=
0
;
function
selectElement()
{
var
key
=
window.event.keyCode
if
(divObj.style.display
==
""
)
{
if
(key
==
40
)
{
//
divObj.childNodes[k].style.background="#0080ff";
if
(tag
==
0
)
{}
else
{
k
++
;
if
(k
>=
num)
{
k
=
0
;
}
}
}
if
(key
==
38
)
{
//
divObj.childNodes[k].style.background="#0080ff";
k
--
;
if
(k
<
0
)
{
k
=
num
-
1
;
}
}
for
(
var
i
=
0
;i
<
num;i
++
)
{
if
(i
==
k)
{
divObj.childNodes[i].style.background
=
"
#0080ff
"
;
document.getElementById(
"
key
"
).value
=
divObj.childNodes[i].innerText;
}
else
{
divObj.childNodes[i].style.background
=
""
;
//
document.getElementById("key").value=divObj.childNodes[i].innerText;
}
}
}
tag
=
1
;
if
(key
==
13
)
{
if
(divObj.style.display
==
""
)
{
divObj.style.display
=
"
none
"
;
}
else
{
divObj.style.display
=
""
;
}
}
}
//
******************************************* 测试数组 ***********************************
var
arr
=
"
A,B,C,D,E,F,H
"
;
var
t
=
0
;
function
getArray()
{
var
str
=
document.getElementById(
"
AVG
"
).value;
var
alist
=
arr.split(
'
,
'
);
for
(
var
i
=
0
;i
<
alist.length;i
++
)
{
if
(alist[i]
==
str)
{
t
=
1
;
}
}
if
(t
==
1
)
{
arr
=
""
;
for
(
var
i
=
0
;i
<
alist.length;i
++
)
{
if
(alist[i]
!=
str)
{
arr
+=
alist[i]
+
"
,
"
;
}
}
arr
=
arr.substring(
0
,arr.length
-
1
);
t
=
0
;
}
else
{
arr
=
arr
+
"
,
"
+
str;
}
alert(arr);
}
</
script
>
</
head
>
<
body
>
当一个字符数组含有某一个元素时删除它,如果没有该元素,则增加到数组中去
<
br
>
<
input
id
="AVG"
type
=text
value
="输入字符"
/>
<
input
type
=button
onclick
="getArray()"
value
="测试数组"
/><
p
><
p
><
p
><
p
><
p
>
<
script
language
='javascript'
>
document.write(getstring())
</
script
>
双击显示下拉列表后可以用键盘的上下键选择,也可以用回车键显示下拉列表
<
div
id
="Menu"
style
="background:#008080;display:none;cursor:default"
>
<
div
onmouseover
="mouseOver(this)"
onmouseout
="mouseOut(this)"
onclick
="mouseClick(this)"
><
span
style
="100%"
>
AAA
</
span
></
div
>
<
div
onmouseover
="mouseOver(this)"
onmouseout
="mouseOut(this)"
onclick
="mouseClick(this)"
><
span
>
bbb
</
span
></
div
>
<
div
onmouseover
="mouseOver(this)"
onmouseout
="mouseOut(this)"
onclick
="mouseClick(this)"
><
span
>
ccc
</
span
></
div
>
<
div
onmouseover
="mouseOver(this)"
onmouseout
="mouseOut(this)"
onclick
="mouseClick(this)"
><
span
>
ddd
</
span
></
div
>
<
div
onmouseover
="mouseOver(this)"
onmouseout
="mouseOut(this)"
onclick
="mouseClick(this)"
><
span
>
eee
</
span
></
div
>
<
div
onmouseover
="mouseOver(this)"
onmouseout
="mouseOut(this)"
onclick
="mouseClick(this)"
><
span
>
fff
</
span
></
div
>
<
div
onmouseover
="mouseOver(this)"
onmouseout
="mouseOut(this)"
onclick
="mouseClick(this)"
><
span
>
AAA
</
span
></
div
>
<
div
onmouseover
="mouseOver(this)"
onmouseout
="mouseOut(this)"
onclick
="mouseClick(this)"
><
span
>
bbb
</
span
></
div
>
<
div
onmouseover
="mouseOver(this)"
onmouseout
="mouseOut(this)"
onclick
="mouseClick(this)"
><
span
>
ccc
</
span
></
div
>
<
div
onmouseover
="mouseOver(this)"
onmouseout
="mouseOut(this)"
onclick
="mouseClick(this)"
><
span
>
ddd
</
span
></
div
>
<
div
onmouseover
="mouseOver(this)"
onmouseout
="mouseOut(this)"
onclick
="mouseClick(this)"
><
span
>
eee
</
span
></
div
>
</
div
>
</
body
>
</
html
>
查看全文
相关阅读:
Delphi管理多线程之线程局部存储:threadvar
Delphi多线程编程--线程同步的方法(事件、互斥、信号、计时器)简介
Delphi线程同步(临界区、互斥、信号量)
Delphi多线程的OnTerminate属性(附加一个关于临界区线程同步的例子)
Delphi中怎么结束线程(这个线程是定时执行的)(方案二)
Delphi中怎么结束线程(这个线程是定时执行的)(方案一)
Delphi中线程类TThread实现多线程编程2---事件、临界区、Synchronize、WaitFor……
Docker数据卷
Docker获取镜像以及相关指令
Docker安装
原文地址:https://www.cnblogs.com/jacklong/p/1041448.html
最新文章
计算机网络复习笔记1
跟左神学算法6 进阶数据结构(二叉树)
跟左神学算法5 基础数据结构(链表相关)
跟左神学算法4 基础数据结构(矩阵相关)
跟左神学算法3 基础数据结构(队列和栈)
跟左神学算法2 排序相关
跟左神学算法1 算法入门
flask简单了解
django中的setting最佳配置小结
django基础知识之Response对象
热门文章
gevent 传参, 中文编码
Python + gevent模块对单个接口进行并发测试 1
Flask的配置文件
Mac下安装配置Python2和Python3并相互切换使用 转
MAC终端下常用Git命令
MAC office2016 安装及激活(试了一下,靠谱, 非常感谢原作者)
charles破解激活方法,注册码
Delphi线程简介---Create及其参数、Resume、Suspend
Delphi测试线程的时间
Delphi线程的终止
Copyright © 2011-2022 走看看