请问各位大大~按钮里面的值怎么传入文本域里啊? - Web 开发 / 其他
这是我的JSP代码:
希望只是在这个静态页面里就完成按钮里的值传入文本域里~谢谢各位大大啦~
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type="text/javascript">
function check_null(){
//输入帐号
if(document.getElementById('username').value=="")
{
alert("请输入帐号!");
document.getElementById('username').focus();
return false;
}
if(document.getElementById('username').value.length<19||document.getElementById('username').value.length>19)
{
alert("帐号必须为19位!");
document.getElementById('username').focus();
return false;
}
//输入密码
if(document.getElementById('userpwd').value=="")
{
alert("请输入密码!");
document.getElementById('userpwd').focus();
return false;
}
if(document.getElementById('userpwd').value.length<6||document.getElementById('userpwd').value.length>6)
{
alert("密码必须为6位!");
document.getElementById('userpwd').focus();
return false;
}
}
</script>
<style type="text/css">
<!--
.STYLE1 {
font-size: 24px;
font-weight: bold;
}
-->
</style>
</head>
<body>
<p align="center" class="STYLE1">欢迎使用ATM自动提款机</p>
<form name="form1" method="post" action="servlet/ADDATMdenglu"
onSubmit="return check_null();">
<table width="250" height="119" border="1" align="center">
<tr>
<td width="71" height="58">
<div align="center" class="username">
帐号:
</div>
</td>
<td width="113">
<label>
<div align="left" >
<input type="text" name="username" id="username">
</div>
</label>
</td>
</tr>
<tr>
<td height="53">
<div align="center" class="userpwd" >
密码:
</div>
</td>
<td>
<div align="left">
<label>
<input type="password" name="userpwd" id="userpwd">
</label>
</div>
</td>
</tr>
</table>
<p>
</p>
<table width="202" border="1" align="center">
<tr>
<td width="60">
<div align="center">
<input type="button" name="1" value="1">
</div>
</td>
<td width="60">
<div align="center">
<input type="button" name="2" value="2">
</div>
</td>
<td width="60">
<div align="center">
<input type="button" name="3" value="3">
</div>
</td>
</tr>
<tr>
<td>
<div align="center">
<input type="button" name="4" value="4">
</div>
</td>
<td>
<div align="center">
<input type="button" name="5" value="5">
</div>
</td>
<td>
<div align="center">
<input type="button" name="6" value="6">
</div>
</td>
</tr>
<tr>
<td>
<div align="center">
<input type="button" name="7" value="7">
</div>
</td>
<td>
<div align="center">
<input type="button" name="8" value="8">
</div>
</td>
<td>
<div align="center">
<input type="button" name="9" value="9">
</div>
</td>
</tr>
<tr>
<td>
<div align="center">
<input type="button" name="0" value="0">
</div>
</td>
<td>
<div align="center">
<input type="reset" name="reset" value="重置">
</div>
</td>
<td>
<div align="center">
<input type="submit" name="submit" value="确定">
</div>
</td>
</tr>
</table>
</form>
</body>
</html>
[解决办法]
加上这些
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
<script type="text/javascript">
<!--
var obj ;
$(function(){
$("input[type='button']").click(function(){
{
//val = val+$(this).val();
obj.value = obj.value+$(this).val();
}
})
$("#username").focus();
obj = document.getElementById('username');
$("#username").focus(function(){
obj=this;
})
$("#userpwd").focus(function(){
obj = this;
})
})
//-->
</script>