点击添加按钮不进addItem() 找不到错在哪儿啊 谢谢谢谢
<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<html>
<head>
<title>增加物料页面</title>
<script type="text/javascript">
function addItem() {
if (trim(document.getElementById("itemName").value) == "") {
alert("物料名称不能为空!");
document.getElementById("itemName").focus();
return;
}
with (document.getElementById("add_itermForm")) {
method = "post";
action = "item.do?command=add";
submit();
}
}
function goBack() {
window.self.location = "item.do?command=list";
}
</script>
</head>
<body>
<table>
<tr>
<td height="26">物料名称:</td>
<td><input name="itemName" type="text" id="itemName" size="20" maxlength="20"></td>
</tr>
<tr>
<td height="26">物料规格:</td>
<td><label>
<input name="spec" type="text" id="spec" size="20" maxlength="20">
</label></td>
</tr>
<tr>
<td height="26">型 号:</td>
<td><input name="pattern" type="text" id="pattern" size="20" maxlength="20"></td>
</tr>
</table>
<hr width="97%" align="center" size=0>
<div align="center">
<input name="btnAdd" type="button" value="添加" id="btnAdd" onclick="addItem()" >
<input name="" type="button" value="返回" id="btnBack" onClick="goBack()">
</div>
</body>
</html>
<%@ page language="java" pageEncoding="utf-8"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<html>
<head>
<title>增加物料页面</title>
<script type="text/javascript">
function addItem() {
if (trim(document.getElementById("itemName").value) == "") {
alert("物料名称不能为空!");
document.getElementById("itemName").focus();
return;
}
with (document.getElementById("add_itermForm")) {
method = "post";
action = "item.do?command=add";
submit();
}
}
function goBack() {
window.self.location = "item.do?command=list";
}
</script>
</head>
<body>
<table>
<tr>
<td height="26">物料名称:</td>
<td><input name="itemName" type="text" id="itemName" size="20" maxlength="20"></td>
</tr>
<tr>
<td height="26">物料规格:</td>
<td><label>
<input name="spec" type="text" id="spec" size="20" maxlength="20">
</label></td>
</tr>
<tr>
<td height="26">型 号:</td>
<td><input name="pattern" type="text" id="pattern" size="20" maxlength="20"></td>
</tr>
</table>
<hr width="97%" align="center" size=0>
<div align="center">
<input name="btnAdd" type="button" value="添加" id="btnAdd" onclick="addItem()" >
<input name="" type="button" value="返回" id="btnBack" onClick="goBack()">
</div>
</body>
</html>
if (document.getElementById("itemName").value.trim() == "") {
楼主改成上面一个试试,我记得prototype框架里给string类型的加了个原型方法就是trim(),可以去掉前后空格。