ajax的hide隐藏问题解决方法
人气:0
我的页面上有两个table,调用ajax之后隐藏掉一个,然后用html拼出另一个table,结果新的table最上面有个undefined,这个是怎么引起的,要怎么解决下呢?详细代码如下:
<script type="text/javascript">
$(function(){
if($.browser.msie)
{
$("#country").get(0).attachEvent("onpropertychange",function (o){
var countr = o.srcElement.value;
$("#tabb1").hide();
$.ajax({
type: "post",
url: "/yoblhtjfx/queryCountryAjax.action",
data: "country="+countr+"&jsoncallback=?",
dataType: "json",
success: function(json)
{
var tableHTML;
tableHTML+="<table id='tabb1' border='1' width='100%'>";
tableHTML+="<tr>";
tableHTML+="<td style='text-align: center' >选择</td>";
tableHTML+="<td style='text-align: center' >区域码</td>";
tableHTML+="<td style='text-align: center' >国别名称</td>";
tableHTML+="</tr>";
var list = json.list;
for(var i=0;i<list.length;i++)
{
tableHTML+="<tr>";
tableHTML+="<td style='text-align: center'><input type='radio' name='radioo' value='"+list[i][1]+"' /></td>";
tableHTML+="<td style='text-align: center'>"+list[i][0]+"</td>";
tableHTML+="<td style='text-align: center'>"+list[i][1]+"</td>";
tableHTML+="</tr>";
}
tableHTML+="</table>";
$("#querycountrydiv").html(tableHTML);
}
});
});
}
});
function returnVal()
{
var valu;
for(var i = 0;i < document.getElementsByName("radioo").length;i++)
{
if(document.getElementsByName("radioo")[i].checked == true)
{
valu = document.getElementsByName("radioo")[i].value;
}
}
window.opener.document.getElementById("foreignUnitCountry").value = valu;
window.close();
}
</script>
</head>
<body>
<div align="center" style="width:100%;">
输入名称搜索:
<input id="country" name="country" value="">
</div>
<hr id="hr" />
<div id="querycountrydiv" name="querycountrydiv" style="width:100%; height:80%; overflow:auto; border:1px solid #000000;">
<table id="tabb1" border="1" width="100%">
<tr>
<td style="text-align: center" nowrap="nowrap">选择</td>
<td style="text-align: center" nowrap="nowrap">区域码</td>
<td style="text-align: center" nowrap="nowrap">国别名称</td>
</tr>
<c:forEach items="${list}" var="list">
<tr>
<td style="text-align: center" nowrap="nowrap"><input type="radio" name="radioo" value="${list[1] }" /></td>
<td style="text-align: center" nowrap="nowrap">${list[0] }</td>
<td style="text-align: center" nowrap="nowrap">${list[1] }</td>
</tr>
</c:forEach>
</table>
</div><br>
<hr id="hr" />
<div>
<input id="button" type="button" value="确定" onclick="returnVal();" />
<input id="button" type="button" value="关闭" onclick="window.close();" />
</div>
</body>
</html>
是上面代码中某段代码出现了语法错误,如下是修改的代码段:
success: function(json) {
var tableHTML = ”;
…
复制代码 代码如下:
<script type="text/javascript">
$(function(){
if($.browser.msie)
{
$("#country").get(0).attachEvent("onpropertychange",function (o){
var countr = o.srcElement.value;
$("#tabb1").hide();
$.ajax({
type: "post",
url: "/yoblhtjfx/queryCountryAjax.action",
data: "country="+countr+"&jsoncallback=?",
dataType: "json",
success: function(json)
{
var tableHTML;
tableHTML+="<table id='tabb1' border='1' width='100%'>";
tableHTML+="<tr>";
tableHTML+="<td style='text-align: center' >选择</td>";
tableHTML+="<td style='text-align: center' >区域码</td>";
tableHTML+="<td style='text-align: center' >国别名称</td>";
tableHTML+="</tr>";
var list = json.list;
for(var i=0;i<list.length;i++)
{
tableHTML+="<tr>";
tableHTML+="<td style='text-align: center'><input type='radio' name='radioo' value='"+list[i][1]+"' /></td>";
tableHTML+="<td style='text-align: center'>"+list[i][0]+"</td>";
tableHTML+="<td style='text-align: center'>"+list[i][1]+"</td>";
tableHTML+="</tr>";
}
tableHTML+="</table>";
$("#querycountrydiv").html(tableHTML);
}
});
});
}
});
function returnVal()
{
var valu;
for(var i = 0;i < document.getElementsByName("radioo").length;i++)
{
if(document.getElementsByName("radioo")[i].checked == true)
{
valu = document.getElementsByName("radioo")[i].value;
}
}
window.opener.document.getElementById("foreignUnitCountry").value = valu;
window.close();
}
</script>
</head>
<body>
<div align="center" style="width:100%;">
输入名称搜索:
复制代码 代码如下:
<input id="country" name="country" value="">
</div>
<hr id="hr" />
<div id="querycountrydiv" name="querycountrydiv" style="width:100%; height:80%; overflow:auto; border:1px solid #000000;">
<table id="tabb1" border="1" width="100%">
<tr>
<td style="text-align: center" nowrap="nowrap">选择</td>
<td style="text-align: center" nowrap="nowrap">区域码</td>
<td style="text-align: center" nowrap="nowrap">国别名称</td>
</tr>
<c:forEach items="${list}" var="list">
<tr>
<td style="text-align: center" nowrap="nowrap"><input type="radio" name="radioo" value="${list[1] }" /></td>
<td style="text-align: center" nowrap="nowrap">${list[0] }</td>
<td style="text-align: center" nowrap="nowrap">${list[1] }</td>
</tr>
</c:forEach>
</table>
</div><br>
<hr id="hr" />
<div>
<input id="button" type="button" value="确定" onclick="returnVal();" />
<input id="button" type="button" value="关闭" onclick="window.close();" />
</div>
</body>
</html>
是上面代码中某段代码出现了语法错误,如下是修改的代码段:
success: function(json) {
var tableHTML = ”;
…
加载全部内容