更改按钮单击JSP的背景色 [英] Change background color on button click jsp

查看:247
本文介绍了更改按钮单击JSP的背景色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开始学习网络编程,我想实现一个可更改背景颜色的应用程序.我的页面上有4个按钮.我做了什么但这是行不通的.我知道,我可以使用js.但这是不对的.请帮帮我.

I recently started learning web programming and I want to implement an application that changes the background color. There are 4 buttons on my page. I did something. But It does not work. I know, that i can use js. But it will not be right. Please, help me.

<%@ 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之后再次将其打开.

You should close the java scriptlet tag before typing html, and open it again after typing html.

%>
<body style='background-color: red;'>
<%

您可能要从<form>中删除action属性,因为该表单应该传递到相同的url.

And you may want to remove the action attribute from the <form> since the form should be passed to the same url.

这篇关于更改按钮单击JSP的背景色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆