|  | 
 
| 原生方式有更好的兼容性,对于早期IE和现代浏览器都能有好支持。 
 复制代码
 function ajax() {
        //创建核心对象
        xhr = null;
        if (window.XMLHttpRequest) {// 新版本的浏览器可以直接创建XMLHttpRequest对象
            xhr = new XMLHttpRequest();
        } else if (window.ActiveXObject) {// IE5或IE6没有XMLHttpRequest对象
            xhr = new ActiveXObject("Microsoft.XMLHTTP");
        }
        //编写回调函数
        xhr.onreadystatechange = function() {
            if (xhr.readyState == 4 && xhr.status == 200) {
                //alert(xhr.responseText)
                                var result=xhr.responseText;
                                result=result.slice(0,result.length-1)                        
                        var arr=result.split(",")
                        var obj;                
                        var j;         
                        for(j = 0,len=arr.length; j < len; j++)  {
                                  obj= document.getElementById("day_"+arr[j]);
                                        
                                        
                                  
                                  if (obj) {
                    obj.className +='ttasp';        
                 //console.log(obj);
                  }
                                }
                                
            }
        }
        //open设置请求方式和请求路径
        xhr.open("get", "../ttasp/action.asp");//一个url还传递了数据,后面还可以写是否同步
        //send 发送
        xhr.send();
    }
        
        ajax();
 下面是JQ方式:
 
 复制代码$.ajax({
  type: "GET",
  url: "../ttasp/action.asp",
  data: {    
    act: "qd"
  },
  success:function(result){
                        //$("#div1").html(result);
                        result=result.slice(0,result.length-1)                        
                        var arr=result.split(",")
                        var obj;                         
                        for (const elem of arr) {
                                    obj= $("#day_"+elem);
                                        console.log(obj);
                                        //obj.setAttribute("style","background-image:url(../ttasp/bg.jpg);background-repeat:no-repeat; background-size:100% 100%;  -moz-background-size:100% 100%;")
                                  obj.addClass('ttasp');
                                }
                }
});
 | 
 |