-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwo_input.html
173 lines (149 loc) · 4.95 KB
/
two_input.html
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>two input</title>
<link rel="stylesheet" href=" ../css/bootstrap.min.css">
<script src="../jquery-3.3.1.min.js"></script>
<script src="../js/bootstrap.min.js"></script>
<style>
*{
margin: 0;
padding: 0;
}
.addbg{
background:#87A900;
}
p.item{
height: 20px;
/*border: 1px solid red;*/
overflow: hidden;
}
.div_content1{
width: 150px;
height: 100px;
margin: 0 0 0 36px;
border:solid #87A900 2px;
border-top:0;
display:none;
position: absolute;
overflow: auto;
}
.div_content2{
width: 250px;
height: 100px;
margin:0 0 0 232px;
border:solid #87A900 2px;
border-top:0;
display:none;
position: absolute;
overflow: auto;
}
</style>
</head>
<body>
<div>
<div class="div1" style="display: inline-block;vertical-align: top">
<div class="form-inline">
<label class="text-success">主类</label>
<input class="input1 form-control" style="width: 150px" onKeyup="KeyupEvent(event,this)">
<div class="div_content1"></div>
</div>
</div>
<div class="div2" style='display:inline-block;vertical-align: center;'>
<div class="form-inline">
<label type="text" class="text-success">从类</label>
<input class="input2 form-control" style="width: 250px" onKeyup="KeyupEvent(event,this)">
</div>
</div>
<div class="div_content2"></div>
</div>
<script>
var data=[
'abc',
'acc',
'awe',
'zxc',
'qwe'
]
function getContent(obj) {
var input1 = $.trim($(obj).val());
if (input1 == "") {
$(".div_content1").hide().html("");
return false;
}
var html = "";
for (var i = 0; i < data.length; i++) {
//indexof返回被选元素在字符串中首次出现的位置,没有则返回-1
//onmouseenter表示鼠标移到元素上时触发指定事件
if (data[i].indexOf(input1) >= 0) {
html = html + "<div><input type='checkbox' style='display: inline-block'><p class='item' onmouseenter='getFocus(this)' onClick='getCon(this);' style='display: inline-block;'>" + data[i] + "</p></div>"
}
}
if (html != "") {
$(".div_content1").show().html(html);
} else {
$(".div_content1").hide().html("");
}
}
function getFocus(obj){
$(".item").removeClass("addbg");
$(obj).addClass("addbg");
}
function getCon(obj){
var value = $(obj).text();
$(obj).parent().parent().parent().append("<div><label>从类</label><input type='text' style='width: 250px;'></div>")
// $(obj).parent().parent().find("div").eq(1).find("input").val()
$(".input1").val(value);
$(".div_content1").hide().html("");
}
function KeyupEvent(e,obj) {
if(e.keyCode=='81'&&e.ctrlKey){
//ctrl+q
getContent(obj)
}
else if(e.keyCode=='66'&&e.ctrlKey){
//ctrl+b
getContent2(obj)
}
}
function getContent2(obj) {
var input2 = $.trim($(obj).val());
if (input2 == "") {
$(".div_content2").hide().html("");
return false;
}
var html = "";
for (var i = 0; i < data.length; i++) {
//indexof返回被选元素在字符串中首次出现的位置,没有则返回-1
//onmouseenter表示鼠标移到元素上时触发指定事件
if (data[i].indexOf(input2) >= 0) {
html = html + "<div><input type='checkbox' style='display: inline-block'><p class='item' onmouseenter='getFocus(this)' onClick='getCon2(this);' style='display: inline-block;'>" + data[i] + "</p></div>"
}
}
if (html != "") {
$(".div_content2").show().html(html);
} else {
$(".div_content2").hide().html("");
}
}
function getCon2(obj){
var value;
checkbox2_length=$(".div_content2").find("input:checked").length
if(checkbox2_length==0){
$(".input2").eq(0).val($(obj).text());
}
for(i=0;i<checkbox2_length;i++){
if(i==0){
$(".input2").eq(0).val($(".div_content2").find("input:checked").eq(i).siblings(".item").text());
}else{
$(".div2").append("<div class='form-inline'><label type=\"text\" class=\"text-success\">从类</label> <input class='input2 form-control' style='width: 250px;' onKeyup='KeyupEvent(event,this)'></div>")
value=$(".div_content2").find("input:checked").eq(i).siblings(".item").text()
$(".input2").eq(i).val(value);
}
}
$(".div_content2").hide().html("");
}
</script>
</body>
</html>