首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Ajax >

入门级有关问题

2012-04-17 
入门级问题jquery的ajax和原生js的ajax第一种HTML code!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Tra

入门级问题
jquery的ajax和原生js的ajax

第一种

HTML code
<!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>    <title>Ajax</title>    <script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script>    <script type="text/javascript">        window.onload = function () {            var xmlhttp;            if (window.XMLHttpRequest) {                xmlhttp = new XMLHttpRequest();            }            else {                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");            }            xmlhttp.open("GET", "http://seman.com/ajax.js?version=" + Math.random(), true);            xmlhttp.setRequestHeader("Content-type", "text/javascript");            xmlhttp.send();        }    </script></head><body>    <div style="width:100px;height:100px;background-color:Yellow;">    </div></body></html>


第二种

HTML code
<!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>    <title>Ajax</title>    <script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script>    <script type="text/javascript">        $(window).load(function () {            $.ajax({                url: "http:seman.com/ajax.js?version=" + Math.random(),                dataType:"script"            });        })    </script></head><body>    <div style="width:100px;height:100px;background-color:Yellow;">    </div></body></html>



其中ajax.js 建立在自己电脑的IIS上,主机头seman.com

ajax.js只有一句话
JScript code
document.getElementsByTagName("div")[0].style.backgroundColor = "red";


改变div的颜色

为什么jquery的有效,原生的不行

[解决办法]
在firefox试了下,没发现问题啊,都可以改变颜色阿?
[解决办法]
探讨

在firefox试了下,没发现问题啊,都可以改变颜色阿?

热点排行