当前位置: 代码迷 >> J2EE >> JSP页面中的button旋钮的onclick事件不能触发
  详细解决方案

JSP页面中的button旋钮的onclick事件不能触发

热度:131   发布时间:2016-04-22 02:48:41.0
JSP页面中的button按钮的onclick事件不能触发
JSP页面中的button按钮的onclick事件不能触发,从新发布也没用,两个button按钮都没有用。
  求指点。

<script type="text/javascript">
  
  var xmlHttp;
  
  function createXMLHttpRequest(){
  try{
  xmlHttp=new XMLHttpReques();
  }catch(e){
  try{
  xmlHttp=new ActiveXObject(Msxm12.XMLHTTP);
  }catch(e){
  try{
  xmlHttp=new ActiveXObject(Microsoft.XMLHTTP);
  }catch{
  alert("你的浏览器版本太老了!");
  }
  }
  }
  }
  
  function handlestatechange(){
  if(xmlHttp.readyState==4){
  if(xmlHttp.status==200){
  alert("文件内容:"+xmlHttp.responseText);
  }
  }
  }
  
  function startRequest(){
  createXMLHttpRequest();
  xmlHttp.onreadystatechange=handlestatechange;
  xmlHttp.open("post","web.xml",true);
  xmlHttp.send(null);
  }
  
  function start(){
  alert("11111111111");
  }
   
  </script>
  
  <body>
  This is my JSP page. <br>
  <input type="button" id="bt1" value="提交" onclick="startRequest();">
  <input type="button" id="bt2" value="测试" onclick="start();">
  </body>

------解决方案--------------------
只是你代码写错了而已 不是不能触发
------解决方案--------------------
一般来说,这是页面js有错误导致的,要测试的话把别的js去掉只留触发事件的代码测试即可
可以点击页面左下角的js错误提示看一下是什么错误。
------解决方案--------------------
括弧是不是没对上。
------解决方案--------------------
js错了。用火狐调试js看看什么地方写错了。
------解决方案--------------------
try{
xmlHttp=new ActiveXObject(Microsoft.XMLHTTP);
}catch{
alert("你的浏览器版本太老了!");
}
catch少了(e)

还有你js中还有很多错误、、
给分吧、哈哈
------解决方案--------------------
JS很麻烦,很容易出现错误,学习中...
------解决方案--------------------
js差错的好工具:Firefox
简单一点的直接用错误控制台
工具 - 错误控制台 5.0以上在快捷菜单 - web开发人员 - 错误控制台

更进一步的话,安装firebug插件,可以跟踪js执行情况
------解决方案--------------------
Java code
<html>  <head>    <title>test</title>    <script type="text/javascript">        function test(){            alert("test");        }    function startS(){  alert("11111111111");  }      </script>  </head>  <body>        <body>  <input type="button" id="bt1" value="提交" onclick="startRequest();">  <input type="button" id="bt2" value="测试1" onclick="startS()"><input type="button" id="bt3" value="测试2" onclick="test()">  </body></html>start()这个方法是js内部的,你不能随便叫这个名字啊
------解决方案--------------------
Java code
<html><head><script type="text/javascript">var xmlhttp;function loadXMLDoc(url){xmlhttp=null;if (window.XMLHttpRequest)  {  xmlhttp=new XMLHttpRequest();  }else if (window.ActiveXObject)  {  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");  }if (xmlhttp!=null)  {  xmlhttp.onreadystatechange=state_Change;  xmlhttp.open("GET",url,true);  xmlhttp.send(null);  }else  {  alert("Your browser does not support XMLHTTP.");  }}function state_Change(){if (xmlhttp.readyState==4)  {  if (xmlhttp.status==200)    {    alert("文件内容:"+xmlhttp.status);    }  else    {    alert("Problem retrieving XML data:" + xmlhttp.responseText);    }  }}  function startz(){  alert("11111111111");  }</script></head><body><h2>Using the HttpRequest Object</h2><button onclick="startz()">TEST</button><button onclick="loadXMLDoc('c:/web.xml')">TEST_XML</button>
  相关解决方案