-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest1.html
65 lines (61 loc) · 1.6 KB
/
test1.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
<!DOCTYPE html>
<html>
<head>
<title>CSS让同一行文字和输入框对齐</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
#a {
height:30px;
border:1px solid #ccc;
}
#b {
margin-top:20px;
height:30px;
border:1px solid #ccc;
}
#a input {
width:200px;
height:30px;
border:1px solid red;
}
#b input {
width:200px;
height:30px;
border:1px solid red;
vertical-align:middle;
margin-top:-2px;
margin-bottom:1px;
}
</style>
<span style="white-space:pre"> </span>
</head>
<body>
<select name="" id="sel">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<div id="a"><input />Text1</div>
<div id="b"><input />Text2</div>
</body>
<script src="js/jquery.min.js"> </script>
<script>
var id = document.getElementById("sel");
//var id=$("#sel");
id.onmousedown = function(){//当按下鼠标按钮的时候
this.sindex = this.selectedIndex;//把当前选中的值得索引赋给下拉选中的索引
this.selectedIndex = -2;//把下拉选中的索引改变为-1,也就是没有!
}
id.onmouseout = function(){//当鼠标移开的时候
var index = id.selectedIndex;//获取下拉选中的索引
if(index == -2){//如果为-1,就是根本没有选
this.selectedIndex = this.sindex;//就把下拉选中的索引改变成之前选中的值得索引,就默认选择的是之前选中的值
}
};
// id.addEventListener('change',function(){
// });//单一添加下拉改变事件
$("#sel").change(function(){
alert(($('#sel option:selected').text()));
});
</script>
</html>