本文介绍了在jquery中清除ul标签中的li的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
I want to make autoserch where I add li tag to ul tag
My Code is
<pre lang="HTML">
<div class="row clearfix">
<div class="col-md-11">
<div class="form-group">
<b>
<asp:Label ID="lblTagRegisteredUsers" runat="server" Text="FPS"></asp:Label> <i class="fa text-red">*</i></b>
<div id="lblProcessingTagFPS" class="pull-right" style="display: none;" ><i class="fa fa-refresh fa-spin"></i></div>
<ul id="dvTag" runat="server" name="dvTag" ></ul>
<b></b>
</div>
</div>
</pre>
My javascript function is, for making li tag
<pre lang="Javascript">
$('#dvTag').tagit({
triggerKeys: ['comma', 'enter', 'space', 'semicolon'],
placeholder: 'Enter FPS Code OR Name...',
tagSource: function (request, response) {
//alert("yes");
var alloc = $('#ContentPlaceHolder1_ddlA :selected').text();
var tehsil = $('#ContentPlaceHolder1_ddlT :selected').val();
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "../scm/Search_CS.ashx?act=ul&f=" + request.term + "&alloc=" + alloc + "&tehsil=" + tehsil,
data: "{}",
dataType: "json",
async: true,
beforeSend: function () {
$('#lblProcessingTagFPS').show();
},
complete: function (xhr, textStatus) {
$('#lblProcessingTagFPS').hide();
},
success: function (data) {
mydata = new Array();
for (var i = 0; i < data.length; i++) {
mydata.push({
label: data[i].FPS_ShopName_EN,
value: data[i].FPSCode
});
}
//setup the search to search the label and the description
var matcher = new RegExp($.ui.autocomplete.escapeRegex(request.term), "i");
response($.grep(mydata, function (value) {
return matcher.test(value.label) || matcher.test(value.desc);
}));
}
});
}
});</pre>
When I add li tag it contains div and a tag.
Now I want to remove all li tag from ul tag in jquery on selection index change.
My jquery code is
<pre lang="Javascript">function RemoveList()
{
$('#dvTag').each(function () {
var elem = $('#dvTag');
if (elem.children().length > 1) { elem.children().remove();
}
}
);
}</pre>
It is working but after removing li tag ,again I type text for autoserch,
method in Search_CS.ashx reteun suggested list but on gui ,it is not show list that is why i can select tag.
在Tagit功能中
In Tagit function
return matcher.test(value.label);//this line is not working after removing li tag in RemoveList by elem.children().remove();
推荐答案
这篇关于在jquery中清除ul标签中的li的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!