0

我正在尝试获取使用 JavaScript 的服务器端代码。我究竟做错了什么?

function openUp(name)
{
    document.getElementById(name).style.display =  <%if (Request.ServerVariables["HTTP_USER_AGENT"].Contains("FireFox"))Then %>
        response.write('table-row'); <%else%> response.write('block');
}
4

2 回答 2

2

您的Response.Write声明(大小写不正确)应该在<% %>标签内。您的代码中似乎也有 C# 和VB.NET的奇怪混合。您正在使用以下哪个?

C#

document.getElementById(name).style.display =  
    <% if (Request.ServerVariables["HTTP_USER_AGENT"].Contains("FireFox"))
           Response.Write("'table-row'");
       else
           Response.Write("'block'"); %>; // Semi-colon outside of %> is for JavaScript

VB.NET

document.getElementById(name).style.display =  
    <% If (Request.ServerVariables("HTTP_USER_AGENT").Contains("FireFox")) Then
           Response.Write("'table-row'") 
       Else
           Response.Write("'block'")
       End If %>; // Semi-colon outside of %> is for JavaScript
于 2012-09-26T14:09:54.950 回答
0

要回答您的问题,您可以将代码更新为;

C#

document.getElementById(name).style.display = '<%Response.Write((Request.ServerVariables["HTTP_USER_AGENT"].Contains("FireFox") ? "table-row": "block")); %>';

VB

document.getElementById(name).style.display = '<%Response.Write(IIF(Request.ServerVariables["HTTP_USER_AGENT"].Contains("FireFox"), "table-row", "block")) %>';
于 2012-09-26T14:10:13.777 回答