我找到了这个不错的 jquery 插件标签啦!http://levycarneiro.com/2010/03/tag-it-tag-suggestions-editor-and-autocomplete-in-a-jquery-ui-plugin/并希望将其实现到 ASP.Net 应用程序中。
在检查源代码后,我发现该插件将额外的 li 项(带有删除链接等)添加到 ul 中。
如何在 PostBack 上检索选定的标签?
我找到了这个不错的 jquery 插件标签啦!http://levycarneiro.com/2010/03/tag-it-tag-suggestions-editor-and-autocomplete-in-a-jquery-ui-plugin/并希望将其实现到 ASP.Net 应用程序中。
在检查源代码后,我发现该插件将额外的 li 项(带有删除链接等)添加到 ul 中。
如何在 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