从Jquery中检索选定的标签吧!PostBack插件

本文关键字:标签 PostBack 插件 Jquery 检索 | 更新日期: 2023-09-27 17:50:17

我找到了这个不错的jquery插件标签吧!http://levycarneiro.com/2010/03/tag-it-tag-suggestions-editor-and-autocomplete-in-a-jquery-ui-plugin/,并希望实现它到一个ASP。网络应用程序。

在检查源代码后,我发现,插件在ul中添加了额外的li项(带有删除链接等)。

如何在PostBack中检索选中的标签?

从Jquery中检索选定的标签吧!PostBack插件

@citronas,我使用了这个jQuery标签插件:jQuery Tagit

我对它进行了如下修改,以便从服务器端加载带有标签的插件,并在服务器端检索选定的标签。

    ...<script>
    $(function () {
        var availableTags = $("#<%= hdnDBTags.ClientID %>").val().split(',');
        $('#demo1').tagit({ tagSource: availableTags, select: true });
        $("#<%= btnGetTags.ClientID %>").click(function () {
            getTagsString($('#demo1').tagit('tags'))
        });
        function getTagsString(tags) {
            var string = "";
            for (var i in tags) {
                string += tags[i] + ",";
            }
            $("#<%= hdnSelectedTags.ClientID %>").val(string);
        }
    });
</script>
<asp:HiddenField ID="hdnDBTags" runat="server" />
<asp:HiddenField ID="hdnSelectedTags" runat="server" />
<h1>
    Your Profile</h1>
<p>
    <ul id="demo1" name="nameOfSelect">
    </ul>
    <asp:Button ID="btnGetTags" runat="server" Text="Get Tags" OnClick="btnGetTags_Click" />
</p>

后面的代码:

protected void Page_Load(object sender, EventArgs e)
{
    hdnDBTags.Value = "real_estate,mortgage_lending";
}
protected void btnGetTags_Click(object sender, EventArgs e)
{
    string test = hdnSelectedTags.Value;
    IList<string> array = test.Split(',').ToList();
    array.Remove("");
}

D