本文介绍了在jquery中清除ul标签中的li的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

I want to make autoserch where I add li tag to ul tag
My Code is
<pre lang="HTML">

                &lt;div class="row clearfix"&gt;

                    &lt;div class="col-md-11"&gt;
                        &lt;div class="form-group"&gt;

                            <b>
                                &lt;asp:Label ID="lblTagRegisteredUsers" runat="server" Text="FPS"&gt;&lt;/asp:Label&gt;&nbsp;<i class="fa text-red">*</i></b>
                            &lt;div id="lblProcessingTagFPS" class="pull-right" style="display: none;" &gt;<i class="fa fa-refresh fa-spin"></i>&lt;/div&gt;
                            &lt;ul id="dvTag" runat="server" name="dvTag" &gt;&lt;/ul&gt;

                       <b></b>
                    &lt;/div&gt;


                &lt;/div&gt;
           </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 &lt; 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 &gt; 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 13:56