解决Myeclipse10中使用javascript验证form表单,返回true(false)不支持的问题

文章详细介绍了MyEclipse10中使用JavaScript验证表单时遇到的红色报错问题,并提供了两种解决方案:通过创建HTML或JSP文件并验证错误,以及在MyEclipse界面中调整验证设置来解决。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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应用,问题解决。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值