我用Ajax调用Struts的Action,返回之后想通过xmlHttp.responseText获得的内容写入页面中id="cityOpion"的<div>或<a>中,请问怎么写?我的页面如下:<select name="city">
<option value"">全部</option>
<a id="cityOption"></a>
</select>这个<select>是在一个<table>中,xmlHttp.responseText的内容是一些<option>的东西,用来填充<select>,经测试xmlHttp.responseText的内容是正确的。
我的JavaScript写法是这样的document.getElementById("cityOption").innerHTML=xmlHttp.responseText;但这样浏览器提示是找不到cityOption的对象,不知道为什么,请高手帮帮忙。
<option value"">全部</option>
<a id="cityOption"></a>
</select>这个<select>是在一个<table>中,xmlHttp.responseText的内容是一些<option>的东西,用来填充<select>,经测试xmlHttp.responseText的内容是正确的。
我的JavaScript写法是这样的document.getElementById("cityOption").innerHTML=xmlHttp.responseText;但这样浏览器提示是找不到cityOption的对象,不知道为什么,请高手帮帮忙。
</select>document.getElementById("cityOption").innerHTML='<option value"">全部</option>
' + xmlHttp.responseText
<option value="">全部</option><br>
</select>
我改完之后用你的那个,浏览器没有提示错误,但是下拉框没有显示内容,就连“全部”都没有显示
把页面改成<a id="cityOption">
<select name="city">
<option value="">全部</option><br>
</select>
</a>JavaScript改成document.getElementById("cityOption").innerHTML="<select name=\"city\" id=\"cityOption\"><option value=\"\">全部</option><br>" + xmlHttp.responseText + "</select>";这样就可以了
把全部都放到innerHTML里,哥