【发布时间】:2011-08-17 12:54:23
【问题描述】:
我知道有一个类似的问题,但那个答案并没有解决我的问题。
这是我的应用程序的正常外观:
这就是它在 Javascript 警报后的样子(菜单项的宽度被搞砸了,左边的紫色条在顶部添加了一个额外的部分):
这是我用来调用警报的代码:
private void Alert(string msg)
{
Response.Write("<script language = 'javascript'>window.alert('" + msg + "')</script>");
}
有没有人遇到过这个问题,即使使用默认的 asp.NET 设计,我也遇到过类似的问题。我怎样才能解决这个问题?顺便说一下,我用的是IE 7,在火狐上没问题。
更新:
修复了紫色条的问题,删除了边距。仍在解决菜单宽度问题。
这是我的 CSS:
#menu
{
position: absolute;
left: 78%;
top: 108px;
width: 170px !important;
}
div.menu
{
padding: 4px 0px 4px 8px;
}
div.menu ul
{
list-style: none;
margin: 0px;
padding: 0px;
width: auto;
}
div.menu ul li a, div.menu ul li a:visited
{
background-color: #FFF; /*680840*/
border: 1px #4e667d solid;
height: 20px;
width: 140px;
color: #000; /*FFF*/
display: block;
line-height: 1.35em;
padding: 4px 20px;
text-decoration: none;
white-space: nowrap;
}
div.menu ul li a:hover
{
background-color: #680840;
color: #FFF;
text-decoration: none;
}
.selectedMenu
{
background-color: #680840;
color: #FFF;
text-decoration: none;
}
div.menu ul li a:active
{
background-color: #680840;
color: #cfdbe6;
text-decoration: none;
}
@Sassyboy 更新:
前端:
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<asp:HiddenField Value="" ID="errorMessageHidden" runat="server"/>
<script type="text/javascript">
var alertMsg = document.getElementById('errorMessageHidden');
if (alertMsg != null) alert(alertMsg);
</script>
和 c# 我添加了这个:
errorMessageHidden.Value = "Failed to Select - Test";
【问题讨论】:
-
看起来标题中的空白(或其他内容)正在影响整个页面。您能否在 JS 小提琴或演示链接中包含更多上下文?
-
在
<html>或DTD 声明上方有元素会给出未定义的行为,这就是您所得到的。不将元素插入响应流的开头怎么样。 -
@Matt - 抱歉,页面没有链接,并且不能使用 JS Fiddle,因为页面本身很好,当从我的 C# 文件调用 Alert 方法时,它会产生问题.
-
@Justing M. Keyes - 如何调用 Alert 方法,并将其插入到 标记之后?
标签: c# javascript asp.net css