我一直試圖在調用函數後獲取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