我想在前台提交的时候让<input name="user.id" id="id" type="text" alt="用户名">这个种会跟着radio的值改变,比如我radio如果是选的manager的话,那么<input name="user.id" id="id" type="text" alt="用户名">就会变成<input name="manager.id" id="id" type="text" alt="用户名">,于是我写了一段javascript代码,可是完全没起作用,谁能帮我看看啊 分不多,谢谢啦<%@ page pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
%>
<html>
<head>
<title>主页</title>
<script type="text/javascript">
var id = document.getElementById("id");
var password = document.getElementById("password");
var loginType = document.getElementsByName("loginType");
alert(loginType[0].getAttribute("value"));
if(loginType[0].getAttribute("value").equles("manager"))
{
id.setAttribute("name", "manager.id");
password.setAttribute("name", "manager.password");
}
else
{
id.setAttribute("name", "user.id");
password.setAttribute("name", "user.password");
}
</script>
</head>
<body>
<form action="login.action" method="post">
用户名:<input name="user.id" id="id" type="text" alt="用户名">
密 码:<input name="user.password" id="password" type="password" alt="密码">
<input type="radio" name="loginType" value="manager"> 管理员
<input type="radio" name="loginType" value="user"> 用户
<input type="submit" value="提交"> <input type="reset" value="重置">
</form>
</body>
</html>
<%
String path = request.getContextPath();
%>
<html>
<head>
<title>主页</title>
<script type="text/javascript">
var id = document.getElementById("id");
var password = document.getElementById("password");
var loginType = document.getElementsByName("loginType");
alert(loginType[0].getAttribute("value"));
if(loginType[0].getAttribute("value").equles("manager"))
{
id.setAttribute("name", "manager.id");
password.setAttribute("name", "manager.password");
}
else
{
id.setAttribute("name", "user.id");
password.setAttribute("name", "user.password");
}
</script>
</head>
<body>
<form action="login.action" method="post">
用户名:<input name="user.id" id="id" type="text" alt="用户名">
密 码:<input name="user.password" id="password" type="password" alt="密码">
<input type="radio" name="loginType" value="manager"> 管理员
<input type="radio" name="loginType" value="user"> 用户
<input type="submit" value="提交"> <input type="reset" value="重置">
</form>
</body>
</html>
解决方案 »
- 为什么一定要使用接口呢?
- Quartz 应当导入哪个 Jar 包 ?
- ssh问题,急!!!!!!!!!!!!!!!!
- 请教一个jfreechart 曲线图的问题
- hibernate 主键
- 使用log4j 发现写日志时向两个文件(日志采用DailyRollingFileAppender的方式)同时写日志,困惑?
- 求!jrun的配置方法
- 求救:我自定义了一个标签,为什么总是告诉我找不到标签库描述信息?
- strust+hibernate+spring问题
- 在EJB中要运行一个长时间的操作,该如何处理?
- Spring 找不到AbstractRefreshableConfigApplicationContext,急急急!
- struts2之There is no Action mapped for namespace / and action name
<%
String path = request.getContextPath();
%>
<html>
<head>
<title>主页</title>
<script type="text/javascript">
function aaaa(obj) {
var id = document.getElementById("id");
var password = document.getElementById("password");
//var loginType = document.getElementsByName("loginType");
//alert(loginType[0].getAttribute("value"));
alert("loginType.value:" + obj.value);
if(obj.value == "manager")
//if(loginType[0].getAttribute("value").equles("manager"))
{
id.name = "manager.id";
password.name="manager.password";
// id.setAttribute("name", "manager.id");
// password.setAttribute("name", "manager.password");
}
else
{
id.name = "user.id";
password.name="user.password";
//id.setAttribute("name", "user.id");
// password.setAttribute("name", "user.password");
}
alert(id.name);
alert(password.name);
}
</script>
</head>
<body>
<form action="login.action" method="post">
用户名:<input name="user.id" id="id" type="text" alt="用户名">
密 码:<input name="user.password" id="password" type="password" alt="密码">
<input type="radio" name="loginType" value="manager" onchange="aaaa(this);"> 管理员
<input type="radio" name="loginType" value="user" onchange="aaaa(this);"> 用户
<input type="submit" value="提交"> <input type="reset" value="重置">
</form>
</body>
</html>
1、你可以试试Ajax行不行
2、使用JavaScript的话,你最好在select的OnChange方法上执行会比较好点