//建立XMLHttpRequest对象 var xmlhttp; try{ xmlhttp= new ActiveXObject('Msxml2.XMLHTTP'); }catch(e){ try{ xmlhttp= new ActiveXObject('Microsoft.XMLHTTP'); }catch(e){ try{ xmlhttp= new XMLHttpRequest(); }catch(e){} } }
//建立XMLHttpRequest对象 var xmlhttp; try{ xmlhttp= new ActiveXObject('Msxml2.XMLHTTP'); }catch(e){ try{ xmlhttp= new ActiveXObject('Microsoft.XMLHTTP'); }catch(e){ try{ xmlhttp= new XMLHttpRequest(); }catch(e){} } }
另外,id可以只用数字来表示吗?
var insertFkDiv22 = document.createElement('div');
insertFkDiv22.innerHTML="";
创建过后可以直接document.getElementById('id');
我再补充说明一下:
我首先利用var 定义了一个DIV
var a='<div id=a>123</div>'
然后我想如何取得这个a.div 的值,即取得"123"
假设我首先定义:
var a='<div>123,4,5</div>'
那么以split(",")取得值,即:
分别取得:
123
4
5
这三个值
<script type="text/javascript">
<!--
//建立XMLHttpRequest对象
var xmlhttp;
try{
xmlhttp= new ActiveXObject('Msxml2.XMLHTTP');
}catch(e){
try{
xmlhttp= new ActiveXObject('Microsoft.XMLHTTP');
}catch(e){
try{
xmlhttp= new XMLHttpRequest();
}catch(e){}
}
}
function getPart(url){
xmlhttp.open("get",url,true);
xmlhttp.onreadystatechange = function(){
if(xmlhttp.readyState == 4)
{
if(xmlhttp.status == 200)
{
if(xmlhttp.responseText!=""){
document.getElementById("partdiv").innerHTML = unescape(xmlhttp.responseText);
}
}
else{
document.getElementById("partdiv").innerHTML = "";
}
}
}
xmlhttp.setRequestHeader("If-Modified-Since","0");
xmlhttp.send(null);
}setInterval("getPart('asp/srm/count.asp')",1000)
//-->
</script>
<SCRIPT LANGUAGE="JavaScript">
alert (document.getElementById("partdiv").innerHTML)</script>
现在的问题是红色那句无法运行
也就是说我无法取得上段JS代码中定义的partdiv.innerhtml
请问如何实行啊
<!--
//建立XMLHttpRequest对象
var xmlhttp;
try{
xmlhttp= new ActiveXObject('Msxml2.XMLHTTP');
}catch(e){
try{
xmlhttp= new ActiveXObject('Microsoft.XMLHTTP');
}catch(e){
try{
xmlhttp= new XMLHttpRequest();
}catch(e){}
}
}
function getPart(url){
xmlhttp.open("get",url,true);
xmlhttp.onreadystatechange = function(){
if(xmlhttp.readyState == 4)
{
if(xmlhttp.status == 200)
{
if(xmlhttp.responseText!=""){
document.getElementById("partdiv").innerHTML = unescape(xmlhttp.responseText);
}
}
else{
document.getElementById("partdiv").innerHTML = "";
}
}
}
xmlhttp.setRequestHeader("If-Modified-Since","0");
xmlhttp.send(null);
}setInterval("getPart('asp/srm/count.asp')",1000)
//-->
</script>
<SCRIPT LANGUAGE="JavaScript">
alert (document.getElementById("partdiv").innerHTML)</script>现在的问题是红色那句无法运行
也就是说我无法取得上段JS代码中定义的partdiv.innerhtml
请问如何实行啊
alert (document.getElementById("partdiv").innerHTML)
}
还是不能弹出alert框
方法是对的 只是你用的地方可能弹不出 要不你在那加个label 你用JS 给label赋值 语句就写在getPart()函数里 这样也能看到你要的效果啊
事实上partdiv中有通ajax 异步取得的数据啊