Myeclipse10存在一个Bug,使用javascript验证form表单,返回true(false)不支持,
例如代码:
Myeclipse10中 onsubmit="return dosubmit()"
会显示红色 报错,程序运行 js验证失败!
例如如下代码:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 //EN" "http://www.w3.org/TR/html4/loose.dtd" >
<html>
<head>
<title>防止重复提交</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type="text/javascript">
function dosubmit()
{ var username = document.getElementsByName("username")[0];
if(username.value.match(/^\s*$/g))
{
return false;
}
else
{
return true;
}
}
</script>
</head>
<body>
<form action="/MyServlet" method="POST" onsubmit="return dosubmit()">
用户名:<input type="text" name="username" /><br/>
<input id="submit" type="submit" value="提交" />
</form>
</body>
</html>
官网上给的解决方法是:
Steps to Reproduce:
1. Create an HTML or JSP file and open if with either with "Web Page Editor" or "HTML Editor/JSP Editor" (preferably the later).
2. Write the following content:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript">
function foo() {
return false;
}
</script>
</head>
<body>
<button onfocus="return foo()">Push!!!</button>
</body>
</html>
3. Save the file.
4. If the error does not shows up, right click the file into the project tree and select "Validate". ("Web Page Editor" doesn't show the error until you do so).
另外一种解决方案:打开Myeclipse 界面,找到window选项卡,在下拉菜单中打开preferences(首选项),找到Myeclipse节点,单击validation子节点,在右侧的属性列中找到javascript validator for Js files选项,把Bulid复选框的勾去掉,即不选中,点Apply应用,问题解决。