JS中document.getElementById("id").innerHTML之中的id如何用变量表示0
qsnlcax2013.09.03浏览1923次分享举报
无标题文档var str_span;
function main(str_value,str_span)
{
alert(str_span);
//alert(document.getElementById(ajax));
alert(document.getElementById("ajax").innerHTML);
alert("str_span");
//alert(document.test.str_span);
//s = 'str_span';
if(str_value.length==0)
{
alert('用户名为空')
document.getElementById("str_span").innerHTML ='123';
return
}
xmlHttp = GetxmlHttpObject();
if(xmlHttp == null)
{
alert('你的浏览器不支持AJAX');
return ;
}
//else{alert('pass')}
var url = 'php.php'+'?q='+str_value+'&sid='+Math.random();
//alert(url);
xmlHttp.onreadystatechange = stateChange;
xmlHttp.open("GET",url,true);
xmlHttp.send(null)
}
function stateChange()
{
if(xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
//str_span = xmlHttp.responseText;
document.getElementById("str_span").innerHTML= xmlHttp.responseText;
}
}
function GetxmlHttpObject()
{
var xmlHttp = null;
try
{
xmlHttp = new XMLHttpRequest();
}
catch(e)
{
try
{
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}