jsp - 更改按钮单击jsp上的背景颜色
问题描述
我最近开始学习网络编程,我想实现一个改变背景颜色的应用程序。我的页面上有 4 个按钮。我做了点什么。但它不起作用。我知道,我可以使用 js。但这不会是正确的。请帮我。
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action = "apps" method="POST">
<input type="submit" name="red" value ="red" >
<input type="submit" name="blue" value ="blue" >
<input type="submit" name="green" value ="green" >
<input type="submit" name="yellow" value ="yellow" >
<input type="submit" name="reset" value ="reset" >
</form>
<%
String button1Click = request.getParameter("red");
if(button1Click.equals("red")){
<body style='background-color:#red;'>;
}
%>
</form>
</body>
</html>
解决方案
您应该在输入 html 之前关闭 java scriptlet 标记,并在输入 html 后再次打开它。
%>
<body style='background-color: red;'>
<%
并且您可能希望从表单中删除该action
属性,<form>
因为表单应该传递给相同的 url。
推荐阅读
- c# - 当您需要支持多个 ORM 或源时,是通用存储库还是特定存储库?
- android - 在谷歌反向图像搜索中出现错误
- python - 一行中有多个异常。Python
- sql-server - 在 SQL Server 中搜索过程
- powerbi - 在 Power BI 上使用 Bing 地图 REST API 时的身份验证问题
- spring-boot - 如何在 Jackson 中包装 XML 而不是 JSON
- css - Styling a form with flexbox -- labels overflowing nested flexbox divs
- bootstrap-4 - 更改悬停在导航栏品牌 img 上的颜色
- c# - 如何使此代码更实用或更“漂亮”
- c++ - C ++中的算术溢出添加2个DWORD