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,這個是怎么引起的,要怎么解決下呢?詳細代碼如下:
<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)文章
你必須知道的JavaScript 變量命名規(guī)則詳解
在編寫代碼的時候難免涉及到變量的命名問題,不能只要求變量名的語法正確,而忽略了變量命名對代碼可讀性的影響2013-05-05
javascrpt綁定事件之匿名函數(shù)無法解除綁定問題
經(jīng)常聽到有人說,匿名函數(shù)綁定事件不好控制啊,無法解除綁定啊,本文將介紹詳細的解決方法,需要的朋友可以參考下2012-12-12
JavaScript中各數(shù)制轉(zhuǎn)換全面總結(jié)
這篇文章主要介紹了JavaScript中各數(shù)制轉(zhuǎn)換,利用toString的基模式來進行轉(zhuǎn)換,對數(shù)字調(diào)用 toString(10) 與調(diào)用 toString() 它們返回的區(qū)別和相同之處等等都在本文中提及,具體操作步驟大家可查看下文的詳細講解,感興趣的小伙伴們可以參考一下。2017-08-08

