所以我得到了一个典型的错误:
调用Sub时不能使用括号
在我的网页上执行这段代码的时候。
以下是代码:
<select class=<% Response.write("""" & colour & " ")%> selection" name="col" id="chosen">
<option value="none" selected disabled>---</option>
<option value="red">Red</option>
<option value="blue">Blue</option>
<option value="green">Green</option>
</select>
</div>
<br>
<input type="submit" class=<% Response.write("""" & colour & " ")%> btn" value="This one!">
</form>
<%
if chosen.value = Red then PageBody.Attributes.Add("bgcolor", "red")
elseif chosen.value = Blue then PageBody.Attributes.Add("bgcolor", "blue")
elseif chosen.value = Green then PageBody.Attributes.Add("bgcolor", "green")
end if
%>基本上,我试图根据用户从我的HTML下拉菜单中选择的选项来更改页面的背景。我不明白我做错了什么。
发布于 2016-11-07 05:49:56
aspx文件代码
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server" >
<asp:DropDownList ID="chosen1" runat="server" OnSelectedIndexChanged="chosen1_SelectedIndexChanged" AutoPostBack="true">
<asp:ListItem Value="none" Selected="True">---</asp:ListItem>
<asp:ListItem Value="red">Red</asp:ListItem>
<asp:ListItem Value="blue">Blue</asp:ListItem>
<asp:ListItem Value="green">Green</asp:ListItem>
</asp:DropDownList>
</form>
</body>
</html>aspx.cs码
Protected Sub Page_Load(sender As Object, e As EventArgs)
End Sub
Protected Sub chosen1_SelectedIndexChanged(sender As Object, e As EventArgs)
If chosen1.SelectedIndex <> 0 Then
Dim color = chosen1.SelectedValue.ToString()
form1.Attributes.CssStyle.Add("background-color", color)
End If
End Sub看起来不错
https://stackoverflow.com/questions/40457118
复制相似问题