我正在尝试使用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');
}
答案 0 :(得分: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
答案 1 :(得分: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")) %>';