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
>
查看全文
相关阅读:
C# 连接数据库
MySQL数据类型char与varchar中数字代表的究竟是字节数还是字符数?
group by与avg(),max(),min(),sum()函数的关系
MySQL内连接、外连接、交叉连接
Mysql 插入中文错误:Incorrect string value: 'xE7xA8x8BxE5xBAx8F...' for column 'course' at row 1
session和token
session和cookies
sessionid如何产生?由谁产生?保存在哪里?
跨域,你需要知道的全在这里
匈牙利算法模板
原文地址:https://www.cnblogs.com/jacklong/p/1041448.html
最新文章
C语言丨static 函数和普通函数的区别
花别人一半时间学好编程!聪明人是怎么做到的?
“如果上帝是个程序员,万物皆可编”:世界首富马斯克惊人猜想,打开了新世界大门
C++丨引用传递和指针传递有什么区别?知道的都拿到了大厂的offer
C++丨删除链表中间节点的方法详解
万万没想到,为了新冠疫苗宣传,一名16 岁程序员两个月竟做出如此成就...
C语言丨静态关键字static的三种用法总结
开源动物园一日游!技术圈的这些“飞禽走兽”你认识多少?
MongoRepository学习-regex
使用gson将json字符串转为list
热门文章
linux使用mail命令发邮件—第三方smtp
正则表达式分组、断言详解
jquery操作select下拉框的多种方法(选中,取值,赋值等)
TCP的三次握手(建立连接)和四次挥手(关闭连接)
maven工程启动报错。
apache多域名配置
正则表达式匹配:包含且不包含
sublime 正则表达式查找并替换
团队—科学计算器——项目进度
C# 写一个web Api
Copyright © 2011-2022 走看看