ajax的hide隱藏問題解決方法
更新時間:2012年12月11日 11:01:02 作者:
我的頁面上有兩個table,調(diào)用ajax之后隱藏掉一個,然后用html拼出另一個table,結(jié)果新的table最上面有個undefined,這個是怎么引起的
我的頁面上有兩個table,調(diào)用ajax之后隱藏掉一個,然后用html拼出另一個table,結(jié)果新的table最上面有個undefined,這個是怎么引起的,要怎么解決下呢?詳細(xì)代碼如下:
<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' >區(qū)域碼</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">區(qū)域碼</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="關(guān)閉" onclick="window.close();" />
</div>
</body>
</html>
是上面代碼中某段代碼出現(xiàn)了語法錯誤,如下是修改的代碼段:
success: function(json) {
var tableHTML = ”;
…
復(fù)制代碼 代碼如下:
<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' >區(qū)域碼</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%;">
輸入名稱搜索:
復(fù)制代碼 代碼如下:
<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">區(qū)域碼</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="關(guān)閉" onclick="window.close();" />
</div>
</body>
</html>
是上面代碼中某段代碼出現(xiàn)了語法錯誤,如下是修改的代碼段:
success: function(json) {
var tableHTML = ”;
…
相關(guān)文章
FF(火狐)瀏覽器無法執(zhí)行window.close()解決方案
這篇文章主要介紹了FF(火狐)瀏覽器無法執(zhí)行window.close()解決方案,需要的朋友可以參考下2014-11-11解析js如何獲取當(dāng)前url中的參數(shù)值并復(fù)制給input
本篇文章是對js獲取當(dāng)前url中的參數(shù)值并復(fù)制給input的方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06javascript中的遍歷for in 以及with的用法
這篇文章主要介紹了javascript中的類初始化,遍歷for in 以及with的用法,需要的朋友可以參考下2014-12-12輕松學(xué)習(xí)JavaScript函數(shù)中的 Rest 參數(shù)
ES6 引入 rest 參數(shù)用于獲取函數(shù)的多余參數(shù),這樣就不需要使用arguments對象了。rest 參數(shù)搭配的變量是一個數(shù)組,該變量將多余的參數(shù)放入數(shù)組中。下面我們來詳細(xì)了解一下吧2019-05-05JS創(chuàng)建事件的三種方法(實(shí)例代碼)
下面小編就為大家?guī)硪黄狫S創(chuàng)建事件的三種方法(實(shí)例代碼)。小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-05-05javascript學(xué)習(xí)筆記整理(概述、變量、數(shù)據(jù)類型簡介)
這篇文章主要介紹了javascript學(xué)習(xí)筆記整理(概述-變量-數(shù)據(jù)類型),需要的朋友可以參考下2015-10-10