zoukankan
html css js c++ java
JavaScript实现div相对于input的绝对定位[实例:C#用户控件dropDownList]
<%
@ Register TagPrefix
=
"
iewc
"
Namespace
=
"
Microsoft.Web.UI.WebControls
"
Assembly
=
"
Microsoft.Web.UI.WebControls
"
%>
<%
@ Control Language
=
"
c#
"
AutoEventWireup
=
"
false
"
Codebehind
=
"
SelUnit.ascx.cs
"
Inherits
=
"
DXK.Web.component.SelUnit
"
TargetSchema
=
"
http://schemas.microsoft.com/intellisense/ie5
"
%>
<
script
type
="text/javascript"
>
//
Sel_Text.onclick = function()
function
clickSel(obj)
{
if
(divTree.style.display
==
'none')
{
divTree.style.display
=
'';
divTree.style.top
=
findOffsetTop(obj)
+
obj.offsetHeight;
divTree.style.left
=
findOffsetLeft(obj);
}
else
{
divTree.style.display
=
'none';
}
}
document.onclick
=
function
()
{
var
the_obj
=
event.srcElement;
if
((the_obj.id.indexOf('_Sel_Text')
==
-
1
)
&&
(get_ElementById(the_obj, 'divTree')
==
null
))
{
if
(divTree.style.display
==
'')
divTree.style.display
=
'none';
}
}
function
get_ElementById(the_ele,the_id)
{
the_id
=
the_id.toLowerCase();
if
(the_ele.id.toLowerCase()
==
the_id)
return
the_ele;
while
(the_ele
=
the_ele.offsetParent)
{
if
(the_ele.id.toLowerCase()
==
the_id)
return
the_ele;
}
return
(
null
);
}
function
dodblclick(objTV, UCTag)
{
if
(objTV.getTreeNode(objTV.clickedNodeIndex)
!=
undefined)
{
document.getElementById(UCTag
+
'_Sel_Text').value
=
objTV.getTreeNode(objTV.clickedNodeIndex).getAttribute(
"
Text
"
);
document.getElementById(UCTag
+
'_Sel_Value').value
=
objTV.getTreeNode(objTV.clickedNodeIndex).getAttribute(
"
NodeData
"
);
divTree.style.display
=
'none';
}
}
function
findOffsetTop(o)
{
var
t
=
0
;
if
(o.offsetParent)
{
while
(o.offsetParent)
{
t
+=
o.offsetTop;
o
=
o.offsetParent;
}
}
return
t;
}
function
findOffsetLeft(o)
{
var
t
=
0
;
if
(o.offsetParent)
{
while
(o.offsetParent)
{
t
+=
o.offsetLeft;
o
=
o.offsetParent;
}
}
return
t;
}
</
script
>
<
input
id
="Sel_Text"
style
="BACKGROUND-POSITION-X: right; BACKGROUND-IMAGE: url(../images/seltip.jpg); WIDTH: 150px; CURSOR: pointer; BACKGROUND-REPEAT: no-repeat"
readOnly type
="text"
runat
="server"
>
<
INPUT
id
="Sel_Value"
type
="hidden"
runat
="server"
>
<
DIV
id
="divTree"
style
="BORDER-RIGHT: black 1px groove; BORDER-TOP: black 1px groove; DISPLAY: none; OVERFLOW: auto; BORDER-LEFT: black 1px groove; WIDTH: 240px; BORDER-BOTTOM: black 1px groove; POSITION: absolute; HEIGHT: 350px"
><
iewc:treeview
id
="tvUnitList"
runat
="server"
BorderWidth
="0px"
BorderStyle
="None"
Indent
="20"
SelectExpands
="True"
ShowToolTip
="False"
></
iewc:treeview
></
DIV
>
.cs后台代码
1
using
System;
2
using
System.Data;
3
using
System.Drawing;
4
using
System.Web;
5
using
System.Web.UI.WebControls;
6
using
System.Web.UI.HtmlControls;
7
using
Microsoft.Web.UI.WebControls;
8
9
/**/
///
<summary>
10
///
SelUnit 的摘要说明。
11
///
</summary>
12
public
class
SelUnit : System.Web.UI.UserControl
13
{
14
protected
System.Web.UI.HtmlControls.HtmlInputHidden Sel_Value;
15
protected
System.Web.UI.HtmlControls.HtmlInputText Sel_Text;
16
protected
Microsoft.Web.UI.WebControls.TreeView tvUnitList;
17
18
Property
#region
Property
19
/**/
///
<summary>
20
///
[只读]
21
///
</summary>
22
public
string
SelectedText
23
{
24
get
{
return
this
.Sel_Text.Value;}
25
}
26
/**/
///
<summary>
27
///
[只读]
28
///
</summary>
29
public
string
SelectedValue
30
{
31
get
{
return
this
.Sel_Value.Value;}
32
}
33
public
string
SelectedIndex
34
{
35
get
{
return
this
.tvUnitList.SelectedNodeIndex;}
36
set
{
this
.tvUnitList.SelectedNodeIndex
=
value;}
37
}
38
public
string
CssClass
39
{
40
get
{
return
this
.Sel_Text.Attributes[
"
class
"
];}
41
set
{
this
.Sel_Text.Attributes.Add(
"
class
"
, value);}
42
}
43
public
string
Width
44
{
45
get
{
return
this
.Sel_Text.Attributes[
"
width
"
];}
46
set
{
this
.Sel_Text.Attributes.Add(
"
width
"
, value);}
47
}
48
public
bool
AutoPostBack
49
{
50
get
{
return
this
.tvUnitList.AutoPostBack;}
51
set
{
this
.tvUnitList.AutoPostBack
=
value;}
52
}
53
private
bool
_Enabled
=
true
;
54
public
bool
Enabled
55
{
56
get
{
return
this
._Enabled;}
57
set
{
this
._Enabled
=
value;}
58
}
59
#endregion
60
61
private
void
Page_Load(
object
sender, System.EventArgs e)
62
{
63
//
在此处放置用户代码以初始化页面
64
Response.Buffer
=
true
;
65
Response.ExpiresAbsolute
=
System.DateTime.Now.AddSeconds(
-
1
);
66
Response.Expires
=
0
;
67
Response.CacheControl
=
"
no-cache
"
;
68
69
if
(
!
Page.IsPostBack)
70
{
71
string
strUserUnit
=
"
z
"
;
//
默认为全省
72
if
(Session[
"
userinfo
"
]
!=
null
)
73
{
74
DataTable dtUserInfo
=
(DataTable)Session[
"
userinfo
"
];
75
if
(dtUserInfo.Rows.Count
>
0
)
76
strUserUnit
=
dtUserInfo.Rows[
0
][
"
user_unit
"
].ToString().Trim();
77
}
78
79
this
.tvUnitList.Nodes.Clear();
80
this
.InitStatUnitTree(
ref
this
.tvUnitList, strUserUnit,
false
);
81
82
}
83
if
(
this
._Enabled)
84
{
85
this
.Sel_Text.Attributes.Add(
"
onclick
"
,
"
javascript:clickSel(this);
"
);
86
this
.tvUnitList.Attributes.Add(
"
ondblclick
"
,
"
javascript:dodblclick(this,'
"
+
this
.UniqueID
+
"
');
"
);
87
}
88
}
89
90
/**/
///
<summary>
91
///
初始化单位列表,TreeView
92
///
</summary>
93
///
<param name="tv"></param>
94
///
<param name="strUserUnit"></param>
95
///
<param name="ifCheckBox"></param>
96
private
void
InitStatUnitTree(
ref
TreeView tv,
string
strUserUnit,
bool
ifCheckBox)
97
{
98
99
TreeNode tn
=
null
;
100
TreeNode tnChild
=
null
;
101
TreeNode tnGrandChild
=
null
;
102
//
TreeNode root = new TreeNode();
103
//
root.Text = "单位列表";
104
//
tv.Nodes.Add(root);
105
foreach
(DataRow drUnit
in
dtUnit.Rows)
106
{
107
tn
=
DXK.Com.UICommon.tnGetTreeNode(
"
mykey
"
,
"
myvalue
"
);
108
tn.CheckBox
=
ifCheckBox;
109
tv.Nodes.Add(tn);
110
}
111
112
113
/**/
///
<summary>
114
///
返回TreeNode
115
///
</summary>
116
///
<param name="strText"></param>
117
///
<param name="strData"></param>
118
///
<returns></returns>
119
public
static
TreeNode tnGetTreeNode(
string
strText,
string
strData)
120
{
121
TreeNode tn
=
new
TreeNode();
122
tn.CheckBox
=
true
;
123
tn.Text
=
strText;
124
tn.NodeData
=
strData;
125
return
tn;
126
}
127
}
128
}
查看全文
相关阅读:
粤语·简约学习笔记
Linux的网卡由eth0变成了eth1
RedHat 更新CentOS Yum源
Lamp 搭建
像淘宝、京东这样的大型电商网站服务器构架完全部署方案
完成静态服务器——Node.js摸石头系列之四
实现使用Websocket通讯的聊天室——Node.js摸石头系列之六
Node.js摸石头系列目录
Aptana studio 3 修改配色方案
Node.js 的安装和控制台命令——Node.js摸石头系列之一
原文地址:https://www.cnblogs.com/ding0910/p/898313.html
最新文章
HDU 4462 Scaring the Birds(2012年杭州赛区现场赛J题)
最小割
go语言下载
物联网技术框架与标准体系
不重复开发DAO
浅析蜂窝定位技术及位置服务
Java 7:最新特性、代码示例及性能测试
看ExtJs API文档的阅读方法
Ext限制表格输入长度
Struts2 与 freemarker 生成Json、XML 的模板
热门文章
Java 7新功能代码范例
深入浅出URL编码
Canopy聚类算法
Gaussian Mixture Model
关于flume中涉及到时间戳的错误解决,Expected timestamp in the Flume even
贝叶斯法则
Java NIO 系列教程
R语言执行脚本的几种命令
apache 更换掉80端口报错
敏捷团队中测试工程师的绩效管理
Copyright © 2011-2022 走看看