怎么样做能自动判断游览器?
新手上路,请多指教!我的代码如下:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>个人信息查询</title><script type="text/javascript"><!--function Initxmlhttp_request(){ var xmlhttp_request=false;  try {   xmlhttp_request = new ActiveXObject("Msxml2.XMLHTTP");  } catch (e) {   try {    xmlhttp_request = new ActiveXObject("Microsoft.XMLHTTP");   } catch (e) {    xmlhttp_request = false;   }  } if (!xmlhttp_request && typeof XMLHttpRequest!='undefined') {   xmlhttp_request = new XMLHttpRequest();  }  return xmlhttp_request;}function Onsearch(){ var sinfo = document.getElementById("sinfo");  var msgs = document.getElementById("msgs");  msgs.innerHTML = "正在搜索..."; var f = document.form1; var userselects = f.selects.options(f.selects.selectedIndex).value; var userkeyword = f.keyword.value; //接收表单的URL地址 var url = "search.php"; //POST的值  var postStr = "selects="+ userselects +"&keyword="+ userkeyword ; var xmlhttp_request = Initxmlhttp_request(); xmlhttp_request.open("POST", url, true);  xmlhttp_request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");  xmlhttp_request.send(postStr); xmlhttp_request.onreadystatechange = function() {   if (xmlhttp_request.readyState == 4 && xmlhttp_request.status == 200) {   msgs.innerHTML = "";    sinfo.innerHTML = xmlhttp_request.responseText;   } } }//--></script></head>
<body><table width="578" border="0" align="center" cellpadding="0" cellspacing="0">  <tr>    <td height="24" colspan="2" align="center" valign="middle" bgcolor="#4D4D4D">个人信息查询</td>  </tr>  <tr>    <td width="172" height="6" align="center" bgcolor="#202020"></td>    <td width="404" bgcolor="#202020"></td>  </tr>  <tr>    <td height="190" colspan="2" align="center" valign="top"><div id="searchmain">   <div align="left">请选择查询方式并填写查询信息     </div>   <form id="form1" name="form1" method="post" action="">        <label>        <select name="selects" id="selects">          <option value="name">按姓名</option>          <option value="sid">按学号</option>        </select>        <input name="keyword" type="text" id="keyword" />        <input name="Submit" type="button" onclick="Onsearch()" value="查询" />        </label>      </form>      <div id="msgs"></div>    </div>    <div id="sinfo"></div></td>  </tr>  <tr>    <td height="20" colspan="2" align="center" valign="top" ></td>  </tr></table></body></html> 

解决方案 »

  1.   

    // ajax.js/* Function for creating the XMLHttpRequest object.
    * Function takes no arguments.
    * Function returns a browser-specific XMLHttpRequest object
    * or returns the Boolean value false.
    */
    function getXMLHttpRequestObject() {   // Initialize the object:
       var ajax = false;   // Choose object type based upon what's supported:
       if (window.XMLHttpRequest) {
          // IE 7, Mozilla, Safari, Firefox, Opera, most browsers:
          ajax = new XMLHttpRequest();
       } else if (window.ActiveXObject) { // Older IE browsers
          // Create type Msxml2.XMLHTTP, if possible:
          try {
             ajax = new ActiveXObject("Msxml2.XMLHTTP");
          } catch (e) { // Create the older type instead:
             try {
                ajax = new ActiveXObject("Microsoft.XMLHTTP");
             } catch (e) { }
          }
       } // End of main IF-ELSE IF.
       // Return the value:
       return ajax;} // End of getXMLHttpRequestObject() function.
      

  2.   

    加上这个就好用了
    function createXMLHttpRequest(){
    if(window.ActiveXObject){
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else if(window.XMLHttpRequest){
    xmlHttp = new XMLHttpRequest();
    }
    }
      

  3.   

    楼上说的是什么意思,直接加上??我试了没成功。我就是想用AJAX验证一个表单文本框中的内容,把验证结果(可注册/不可注册)显示出来。