1
2
3
4
5
6
7
8
9
10 $(document).ready(function () {
11
12 });
13
14 function UseKeyTo(c) {
15 var inputControl = $(c);
16
17 if (!document.getElementById('province')) {
18 $('body').append('
19 var province = $('#province');
20 $('#province .c').css({
21 'font-size':'14px',
22 'border-radius': '5px',
23 'height': '20px',
24 'width': '100px',
25 'border': '1px solid rgb(30,113,177)',
26 'background-color': 'rgb(219,234,249)',
27 'text-align': 'center',
28 'line-height': '18px',
29 'margin-left': '5px',
30 'margin-top': '5px',
31 'float': 'left',
32 'display': 'inline',
33 'cursor': 'pointer'
34 });
35 $('#province .c').hover(function () { $(this).css("background-color", "rgb(30,113,177)") },
36 function () { $(this).css("background-color", "rgb(219,234,249)") });
37 $("#province .c").click(function () {
38 $('#simple').html($(this).attr('v'));
39 inputControl.val($(this).attr('v'));
40 });
41 $("#province #Kconfirm").click(function () {
42 province.css("display", "none");
43 });
44 $("#province #Kcancel").click(function () {
45 inputControl.val('');
46 province.css("display", "none");
47 });
48 }
49 var province = $('#province');
50 province.show();
51 var _top = inputControl.offset().top - $(window).scrollTop();//inputControl[0].offsetTop - $(window).scrollTop();
52 var _left = inputControl.offset().left - $(window).scrollLeft(); //inputControl[0].offsetLeft - $(window).scrollLeft();
53 province.css("left", inputControl.offset().left + 'px').css("top", inputControl.offset().top + 30 + 'px');
54 var viewWidth = document.documentElement.clientWidth//
55 var viewHeight = document.documentElement.clientHeight;//
56 if ((_left + province.width()) > viewWidth) {
57 //计算div的offset().left
58 var left = (inputControl.offset().left - (_left + province.width() - viewWidth+10)) + 'px';
59 province.css("left", left);
60 }
61 if ((_top + province.height() + 30) > viewHeight) {
62 //计算div的offset().top
63 var top = (inputControl.offset().top - province.height() - 10) + 'px';
64 province.css("top", top);
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