如何显示替换为后的原始元素
How to show the original elements after the replace with?
我有一个名为"frined-replace"的div和一个自动建议字段。当页面加载所示的frined-replacediv中的内容时。当我们在输入字段中写入要搜索的内容时,frined替换将替换为autosuggestion的数据。现在的问题是,当我写一些东西时,frined-replace-div被数据替换,当我擦除我输入的输入字段字符时,我不能重新显示frined-place-div元素。
冰箱更换:
<li style="float:left; width:240; margin:2px 0 4px 2px; border-bottom:1px solid #CCC; background-color:#f90; height:30px;">
<a href="<?php echo $config->baseUrlTs;?>messages?user_id=<?php echo $myusrid;?>" >
<img src="<?php echo $config->baseUrl;?><?php echo $imgs;?>" alt="" width="26" height="26" />
<font style="font-weight:bold; color:white"><?php //global $config;
echo $myusrname;
?></font></a>
</li>
这是自动建议部分:
$("#search").keyup(function(e){
var qr = $("#search").val();
if(qr=="")
{
$("#erase").empty();
return;
}
$.ajax({
url: "<?php echo $config->baseUrl;?>/themes/gr-mist/ajax/inbox-ajax.php?str="+$(this).val()+"&user_id="+<?php echo $userid;?>,
context: document.body,
success: function(data){
$("#frined-replace").replaceWith(data);
//$("#search").val('');
//$('#search').val('').empty();
}
});
});
我刚刚制作了一个片段代码,显示了一个可能的答案
$("#search").keyup(function(e){
var qr = $("#search").val();
if(qr=="") {
$("#frined-replace").html($("#frined-replace-bck").html());
$("#frined-replace-bck").remove();
$("#erase").empty();
return;
}
if (!$('#frined-replace-bck').length) {
var backup = $("#frined-replace").clone();
backup.prop('id', 'frined-replace-bck');
backup.css('display', 'none')
$("#frined-replace").before(backup);
}
//Replace with your ajax call
$("#frined-replace").html('<li>' + qr + '</li>');
//$("#search").val('');
//$('#search').val('').empty();
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div>
<input id="search" type="text"/>
<div id="frined-replace">My initial content</div>
</div>
我修复了它。在显示该div中的数据后,我制作了另一个不显示的div,而不是用frined替换div。
<style type="text/css">
#loadsearch
{
display:none;
width: 250px;
position: absolute;
margin-top: -8px;
height: 100px;
z-index: 1;
margin-left: 2px;
height:auto;
}
</style>
<div id="loadsearch">
</div>
在jquery 中
$("#search").keyup(function(e){
var qr = $("#search").val();
if(qr=="")
{
$("#erase").empty();
$("#loadsearch").hide();
return;
}
$("#loadsearch").empty();
$.ajax({
url: "<?php echo $config->baseUrl;?>/themes/gr-mist/ajax/inbox-ajax.php?str="+qr+"&user_id="+<?php echo $userid;?>,
context: document.body,
success: function(data){
$("#loadsearch").show();
$("#loadsearch").append(data);
//Here i am showing the data inthe div instead of replacing
},
});
});
相关文章:
- 使用 jQuery 的 .on 函数如何获取事件的原始元素
- 如何显示替换为后的原始元素
- jQuery's clone()函数扰乱了原始元素'的属性
- 将jQuery$(this)转换为原始元素
- html5可拖动隐藏原始元素
- AngularJS指令,该指令使用模板中的原始元素类型
- 使用 .on 获取原始元素
- 我可以在 ReactJS 中排除原始元素的子元素吗?
- 独立于原始元素复制元素
- 如何从事件中获取原始元素
- 维护 jQuery.clone() 元素对原始元素的引用
- Js 从数组中删除元素而不更改原始元素
- jQuery 插件,保留对原始元素的引用
- 对数组进行排序并返回一个指示符数组,该数组指示已排序的元素相对于原始元素(new)的位置
- 淡入原始元素而不显示辅助元素
- 放置后移除原始元素
- 如何将数组元素拆分为2,并返回一个已拆分原始元素的新数组
- 如果javascript中存在重复,则从数组中删除所有重复和原始元素
- 链式方法调用对原始元素和克隆元素都不起作用,为什么?
- 使用qTip操作原始元素