下面代码存成OnMouseOver.ascx,也就是说,这是前台代码,后台代码的名字是OnMouseOver.ascx.cs。这是一个用户自定义控件先看代码!!<%@ Control Language="C#" AutoEventWireup="true" CodeFile="OnMouseOver.ascx.cs" Inherits="OnMouseOver" %><script language="JavaScript" type="text/JavaScript" >
//下拉菜单相关代码
var h;
var w;
var l;
var t;
var topMar = 1;
var leftMar = -2;
var space = 1;
var isvisible;
var MENU_SHADOW_COLOR='steelblue';//定义下拉菜单阴影色
var global = window.document
global.fo_currentMenu = null
global.fo_shadows = new Arrayfunction HideMenu()
{
var mX;
var mY;
var vDiv;
var mDiv;
if (isvisible == true)
{
vDiv = document.all("menuDiv");
mX = window.event.clientX + document.body.scrollLeft;
mY = window.event.clientY + document.body.scrollTop;
if ((mX < parseInt(vDiv.style.left)) || (mX > parseInt(vDiv.style.left)+vDiv.offsetWidth) || (mY < parseInt(vDiv.style.top)-h) || (mY > parseInt(vDiv.style.top)+vDiv.offsetHeight))
{
vDiv.style.visibility = "hidden";
isvisible = false;
}
}
}function ShowMenu(vMnuCode,tWidth) {
vSrc = window.event.srcElement;
vMnuCode = "<table id='submenu' cellspacing=1 cellpadding=3 style='width:"+tWidth+"' class=menu onmouseout='HideMenu()'><tr height=23><td nowrap align=left class=MenuBody>" + vMnuCode + "</td></tr></table>"; h = vSrc.offsetHeight;
w = vSrc.offsetWidth;
l = vSrc.offsetLeft + leftMar+4;
t = vSrc.offsetTop + topMar + h + space-2;
vParent = vSrc.offsetParent;
while (vParent.tagName.toUpperCase() != "BODY")
{
l += vParent.offsetLeft;
t += vParent.offsetTop;
vParent = vParent.offsetParent;
} menuDiv.innerHTML = vMnuCode;
menuDiv.style.top = t;
menuDiv.style.left = l;
menuDiv.style.visibility = "visible";0
isvisible = true;
makeRectangularDropShadow(submenu, MENU_SHADOW_COLOR, 4)
}function makeRectangularDropShadow(el, color, size)
{
var i;
for (i=size; i>0; i--)
{
var rect = document.createElement('div');
var rs = rect.style
rs.position = 'absolute';
rs.left = (el.style.posLeft + i) + 'px';
rs.top = (el.style.posTop + i) + 'px';
rs.width = el.offsetWidth + 'px';
rs.height = el.offsetHeight + 'px';
rs.zIndex = el.style.zIndex - i;
rs.backgroundColor = color;
var opacity = 1 - i / (i + 1);
rs.filter = 'alpha(opacity=' + (100 * opacity) + ')';
el.insertAdjacentElement('afterEnd', rect);
global.fo_shadows[global.fo_shadows.length] = rect;
}
}
</script><script language="JavaScript" type="text/JavaScript" >
//菜单列表
var menu1="<a style=font-size:9pt;line-height:14pt; href=' '>一</a><br><a style=font-size:9pt;line-height:14pt; href=' '>二</a><br>"
var menu2="<a style=font-size:9pt;line-height:14pt; href=' '>一</a><br><a style=font-size:9pt;line-height:14pt; href=' '>二</a><br>"
var menu3="<a style=font-size:9pt;line-height:14pt; href=' '>一</a><br><a style=font-size:9pt;line-height:14pt; href=' '>二</a><br>"
var menu4="<a style=font-size:9pt;line-height:14pt; href=' '>一</a><br><a style=font-size:9pt;line-height:14pt; href=' '>二</a><br>"
var menu5="<a style=font-size:9pt;line-height:14pt; href=' '>一</a><br><a style=font-size:9pt;line-height:14pt; href=' '>二</a><br>"
var menu6="<a style=font-size:9pt;line-height:14pt; href=' '>一</a><br><a style=font-size:9pt;line-height:14pt; href=' '>二</a><br>"
var menu7="<a style=font-size:9pt;line-height:14pt; href=' '>一</a><br><a style=font-size:9pt;line-height:14pt; href=' '>二</a><br>"
var menu8="<a style=font-size:9pt;line-height:14pt; href=' '>一</a><br><a style=font-size:9pt;line-height:14pt; href=' '>二</a><br>"
</script>
<meta content="MSHTML 6.00.2900.2802" name="GENERATOR">
<div id=menuDiv style="Z-INDEX: 1000; VISIBILITY: hidden; POSITION: absolute; BACKGROUND-COLOR: #9966cc"></div>
<body onmousemove="HideMenu()" leftMargin=0 topMargin=0>
<table ><!--DWLayoutTable-->
<tr style ="width :100%" align ="center" >
<td><a onmouseover="ShowMenu(menu1,100)" href="DocList.aspx">文档</a></td>
<td><a onmouseover="ShowMenu(menu2,100)" href="DocList.aspx">文档</a></td>
<td><a onmouseover="ShowMenu(menu3,100)" href="DocList.aspx">文档</a></td>
<td><a onmouseover="ShowMenu(menu4,100)" href="DocList.aspx">文档</a></td>
<td><a onmouseover="ShowMenu(menu5,100)" href="DocList.aspx">文档</a></td>
<td><a onmouseover="ShowMenu(menu6,100)" href="DocList.aspx">文档</a></td>
<td><a onmouseover="ShowMenu(menu7,100)" href="DocList.aspx">文档</a></td>
<td><a onmouseover="ShowMenu(menu8,100)" href="DocList.aspx">文档</a></td>
</tr></table></body>上面的内容是一个鼠标放上去就有个下拉菜单显示。现在的是做死了的,不能后台控制,可是,现在需要能够后台控制,下拉菜单的menu通过别的地方来修改,而不用修改这个ascx文件。比如文档,一二,那几个字,我不在这里写,要做一个接口,在别的地方控制要显示的内容。哪位高人来解决一下???
//下拉菜单相关代码
var h;
var w;
var l;
var t;
var topMar = 1;
var leftMar = -2;
var space = 1;
var isvisible;
var MENU_SHADOW_COLOR='steelblue';//定义下拉菜单阴影色
var global = window.document
global.fo_currentMenu = null
global.fo_shadows = new Arrayfunction HideMenu()
{
var mX;
var mY;
var vDiv;
var mDiv;
if (isvisible == true)
{
vDiv = document.all("menuDiv");
mX = window.event.clientX + document.body.scrollLeft;
mY = window.event.clientY + document.body.scrollTop;
if ((mX < parseInt(vDiv.style.left)) || (mX > parseInt(vDiv.style.left)+vDiv.offsetWidth) || (mY < parseInt(vDiv.style.top)-h) || (mY > parseInt(vDiv.style.top)+vDiv.offsetHeight))
{
vDiv.style.visibility = "hidden";
isvisible = false;
}
}
}function ShowMenu(vMnuCode,tWidth) {
vSrc = window.event.srcElement;
vMnuCode = "<table id='submenu' cellspacing=1 cellpadding=3 style='width:"+tWidth+"' class=menu onmouseout='HideMenu()'><tr height=23><td nowrap align=left class=MenuBody>" + vMnuCode + "</td></tr></table>"; h = vSrc.offsetHeight;
w = vSrc.offsetWidth;
l = vSrc.offsetLeft + leftMar+4;
t = vSrc.offsetTop + topMar + h + space-2;
vParent = vSrc.offsetParent;
while (vParent.tagName.toUpperCase() != "BODY")
{
l += vParent.offsetLeft;
t += vParent.offsetTop;
vParent = vParent.offsetParent;
} menuDiv.innerHTML = vMnuCode;
menuDiv.style.top = t;
menuDiv.style.left = l;
menuDiv.style.visibility = "visible";0
isvisible = true;
makeRectangularDropShadow(submenu, MENU_SHADOW_COLOR, 4)
}function makeRectangularDropShadow(el, color, size)
{
var i;
for (i=size; i>0; i--)
{
var rect = document.createElement('div');
var rs = rect.style
rs.position = 'absolute';
rs.left = (el.style.posLeft + i) + 'px';
rs.top = (el.style.posTop + i) + 'px';
rs.width = el.offsetWidth + 'px';
rs.height = el.offsetHeight + 'px';
rs.zIndex = el.style.zIndex - i;
rs.backgroundColor = color;
var opacity = 1 - i / (i + 1);
rs.filter = 'alpha(opacity=' + (100 * opacity) + ')';
el.insertAdjacentElement('afterEnd', rect);
global.fo_shadows[global.fo_shadows.length] = rect;
}
}
</script><script language="JavaScript" type="text/JavaScript" >
//菜单列表
var menu1="<a style=font-size:9pt;line-height:14pt; href=' '>一</a><br><a style=font-size:9pt;line-height:14pt; href=' '>二</a><br>"
var menu2="<a style=font-size:9pt;line-height:14pt; href=' '>一</a><br><a style=font-size:9pt;line-height:14pt; href=' '>二</a><br>"
var menu3="<a style=font-size:9pt;line-height:14pt; href=' '>一</a><br><a style=font-size:9pt;line-height:14pt; href=' '>二</a><br>"
var menu4="<a style=font-size:9pt;line-height:14pt; href=' '>一</a><br><a style=font-size:9pt;line-height:14pt; href=' '>二</a><br>"
var menu5="<a style=font-size:9pt;line-height:14pt; href=' '>一</a><br><a style=font-size:9pt;line-height:14pt; href=' '>二</a><br>"
var menu6="<a style=font-size:9pt;line-height:14pt; href=' '>一</a><br><a style=font-size:9pt;line-height:14pt; href=' '>二</a><br>"
var menu7="<a style=font-size:9pt;line-height:14pt; href=' '>一</a><br><a style=font-size:9pt;line-height:14pt; href=' '>二</a><br>"
var menu8="<a style=font-size:9pt;line-height:14pt; href=' '>一</a><br><a style=font-size:9pt;line-height:14pt; href=' '>二</a><br>"
</script>
<meta content="MSHTML 6.00.2900.2802" name="GENERATOR">
<div id=menuDiv style="Z-INDEX: 1000; VISIBILITY: hidden; POSITION: absolute; BACKGROUND-COLOR: #9966cc"></div>
<body onmousemove="HideMenu()" leftMargin=0 topMargin=0>
<table ><!--DWLayoutTable-->
<tr style ="width :100%" align ="center" >
<td><a onmouseover="ShowMenu(menu1,100)" href="DocList.aspx">文档</a></td>
<td><a onmouseover="ShowMenu(menu2,100)" href="DocList.aspx">文档</a></td>
<td><a onmouseover="ShowMenu(menu3,100)" href="DocList.aspx">文档</a></td>
<td><a onmouseover="ShowMenu(menu4,100)" href="DocList.aspx">文档</a></td>
<td><a onmouseover="ShowMenu(menu5,100)" href="DocList.aspx">文档</a></td>
<td><a onmouseover="ShowMenu(menu6,100)" href="DocList.aspx">文档</a></td>
<td><a onmouseover="ShowMenu(menu7,100)" href="DocList.aspx">文档</a></td>
<td><a onmouseover="ShowMenu(menu8,100)" href="DocList.aspx">文档</a></td>
</tr></table></body>上面的内容是一个鼠标放上去就有个下拉菜单显示。现在的是做死了的,不能后台控制,可是,现在需要能够后台控制,下拉菜单的menu通过别的地方来修改,而不用修改这个ascx文件。比如文档,一二,那几个字,我不在这里写,要做一个接口,在别的地方控制要显示的内容。哪位高人来解决一下???
解决方案 »
- .net做统计图用了OpenFlashChart如何更改X轴上的刻度为时间呢
- 使用js验证客户端,当验证成功时页面不提交服务器。
- 用户离开页面时(点击关闭,点击链接跳转等等)如何弹出一个自定义的选择框(如自定义的DIV)挽留用户,如果用户选择留下来时让页面不继续跳转呢?
- 验证码的无刷新原理是什么?
- 一个小问题--如何能把session中的内容提出来?
- System.Runtime.InteropServices.COMException (0x800A1436): 该文件找不到
- 一个学习网络编程的好地方!
- aspnetMenu怎样来动态控制菜单项是否可见
- 有关 VS.NET Web 安装程序中快捷方式的问题。
- 未将对象引用设置到对象的实例。
- 谁来帮我看看textbox的问题!高难度!
- 哪里有AspnetMenu和DropdownMenu使用说明?
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
string s = @"<script language=""JavaScript"" type=""text/JavaScript"" >"+"\n" +
//菜单列表
@"var menu1=""<a style=font-size:9pt;line-height:14pt; href=' '>一</a><br><a style=font-size:9pt;line-height:14pt; href=' '>二</a><br>"""+"\n"+
@"var menu2=""<a style=font-size:9pt;line-height:14pt; href=' '>一</a><br><a style=font-size:9pt;line-height:14pt; href=' '>二</a><br>"""+"\n"+
@"var menu3=""<a style=font-size:9pt;line-height:14pt; href=' '>一</a><br><a style=font-size:9pt;line-height:14pt; href=' '>二</a><br>"""+"\n"+
@"var menu4=""<a style=font-size:9pt;line-height:14pt; href=' '>一</a><br><a style=font-size:9pt;line-height:14pt; href=' '>二</a><br>"""+"\n"+
@"var menu5=""<a style=font-size:9pt;line-height:14pt; href=' '>一</a><br><a style=font-size:9pt;line-height:14pt; href=' '>二</a><br>"""+"\n"+
@"var menu6=""<a style=font-size:9pt;line-height:14pt; href=' '>一</a><br><a style=font-size:9pt;line-height:14pt; href=' '>二</a><br>"""+"\n"+
@"var menu7=""<a style=font-size:9pt;line-height:14pt; href=' '>一</a><br><a style=font-size:9pt;line-height:14pt; href=' '>二</a><br>"""+"\n"+
@"var menu8=""<a style=font-size:9pt;line-height:14pt; href=' '>一</a><br><a style=font-size:9pt;line-height:14pt; href=' '>二</a><br>"""+"\n"+
"</script>";
this.MenuList.Text = s; this.Page.RegisterStartupScript("menu", s);
}在控件的CS文件注册Javascript, 这是一种实现的方法