[英]In ajax how to hide one div and display sucess in next div
我正在使用ajax通過onkeyup進行搜索。 我想顯示所有結果,如果文本框為空,但如果文本框不為空,則根據鍵入的文本顯示。
<input type="text" onkeyup="searchme()" id="search_id" />
function searchme() {
var value;
value = document.getElementById('search_id').value;
$.ajax({
type: "GET",
url: "get_projectList.php",
data: {value: value,
'table': 'revenue'},
success: function (result)
{$("#resultDiv").html(result); } })
}
我想顯示.resultDiv ID並隱藏以前顯示的結果
<div id="resultDiv"></div>
get_projectList.php包含結果查詢
提前致謝
function searchme() {
var value;
value = document.getElementById('search_id').value;
if(value.length > 0 )
{
$.ajax({
type: "GET",
url: "get_projectList.php",
data: {value: value,
'table': 'revenue'},
success: function (result)
{
$("#project_all").hide();
$("#resultDiv").html(result);
} })
}
else {$("#project_all").show(); }
}
<input type="text" id="search_id" onkeyup="searchme(this)">
<div id="project_all"> // on page load
<li>1</li>
<li>1</li>
<li>1</li>
<li>1</li>
<li>1</li>
</div>
<div id="resultDiv">
</div>
希望可以幫助:)
為什么要將Ajax結果添加到resultDiv,僅將結果添加到project_all div。
仍然有問題,請告訴我.. :)
成功時,首先將html留空,然后添加成功結果。
function searchme() { var value; value = document.getElementById('search_id').value; $.ajax({ type: "GET", url: "get_projectList.php", data: {value: value, 'table': 'revenue'}, success: function (result) { $("#project_all").hide() $("#resultDiv").show(); $("#resultDiv").html(); /* works even thisline is excluded */ $("#resultDiv").html(result); } }) }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.