我一直试图在调用函数后获取xmlhttp.responseText,因为我希望做一些显示和隐藏对象。但似乎我不能匹配innerhtml并显示像按钮这样的对象。从xmlhttp.responseText获取数据
更新JavaScript函数:
function ShowHideDisplay(str)
{
xmlhttp = new XMLHttpRequest();
//It will echo whatever message into this response.text.
if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
document.getElementById("validate").innerHTML = xmlhttp.responseText;
}
//Using test
var successText = "<img src=\"./images/success.gif\" alt=\"Correct!\">Can be used";
document.getElementById("validate").innerHTML = responseText;
if(document.getElementById("validate").innerHTML.test(/success/gmi))
{
document.getElementById("submit").style.visibility = 'visible';
}
else
{
document.getElementById("submit").style.visibility = 'hidden';
}
}
HTML表单:
<input name="Numbers" type="text" id="Numbers" onkeyup="ShowHideDisplay(this);" value=""/>
<span id="validate"></span>
//wants to hide and show upon onkeyup and getting the span id of validate.innerhtml success message
<input name="submit" id="submit" type="submit">
我只需要得到验证值或文本的innerHTML的跨度ID显示和隐藏的按钮。但我尝试不同的方式,但它不能匹配innerhtml文本。 请提醒。
您的代码是否考虑到它需要运行依赖ajax调用的回调函数发送给ajax请求的部分,除非它正在同步进行呼叫? – txominpelu 2012-07-14 23:09:20
nv之前使用ajax。但是有可能获得span id值吗?这样我可以说如果成功了,按钮会显示 – JLearner 2012-07-14 23:16:32