gpt4 book ai didi

c# - 无法从 "jQuery Tag-it!"获取标记

转载 作者:太空宇宙 更新时间:2023-11-03 16:24:34 24 4
gpt4 key购买 nike

我正在使用

jQuery Tag-it!

在输入字段中制作标签,但在输入字段中添加标签后我想从输入字段中检索标签和值,

html代码是:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/jquery-ui.min.js" type="text/javascript" charset="utf-8"></script>
<script src="Scripts/tag-it.js"></script>
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/flick/jquery-ui.css"/>
<link href="Content/jquery.tagit.css" rel="stylesheet" />
<script type="text/javascript">
jQuery(document).ready(function () {
jQuery("#mytags").tagit({
tagSource: function (request, response) {
$.ajax({
type: "POST",
url: "WebForm1.aspx/GetKeyword",
data: "{'match': '" + request.term + "'}",
dataType: "json",
contentType: "application/json",
success: function (data) {
if (data.d != null) {
response($.map(data.d, function (item) {
return {
label: item.Name,
Value: item.Id
}
}));
}
}
});
}
});
});
function myfunction() {
var tagStr = $("#mytags").tagit("tags")
alert("Got tags: " + tagStr);
$('#hiddenTags').val(tagStr);
return false;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<div>
TO :
</div>
<ul id="mytags">
</div>
<asp:Button ID="Button1" runat="server" Text="Send" OnClick="Unnamed1_Click" OnClientClick="myfunction();"/>
</form>
</body>
</html>

C#代码是:

public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
[WebMethod]
public static List<Info> GetKeyword(string match)
{
var qry = GetInfo().Distinct().Where(k => k.Name.ToLower().StartsWith(match.ToLower()));
return qry.ToList();
}

public static IEnumerable<Info> GetInfo()
{
List<Info> list = new List<Info>();
list.Add(new Info { Id = 1, Name = "Tom", Email = "Tom@Email.com" });
list.Add(new Info { Id = 2, Name = "Torex", Email = "Torex@Email.com" });
list.Add(new Info { Id = 3, Name = "Tresa", Email = "Tresa@Email.com" });
list.Add(new Info { Id = 4, Name = "Morgan", Email = "Morgan@Email.com" });
list.Add(new Info { Id = 5, Name = "Paris", Email = "Paris@Email.com" });
list.Add(new Info { Id = 6, Name = "Patrick", Email = "Patrick@Email.com" });
return list;
}

protected void Unnamed1_Click(object sender, EventArgs e)
{

}
}
public class Info
{
public int Id { get; set; }
public string Name { get; set; }
public String Email { get; set; }
}

当我点击按钮获取标签值时: enter image description here

我期望从“发送”按钮获得的值是:带有“id”的 morgan、tom、patrick

最佳答案

尝试控制台日志来检查对象内部的内容,也许它是一个数组,在这种情况下使用 .each。

console.log("Got tags: " + tagStr);

关于c# - 无法从 "jQuery Tag-it!"获取标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12973433/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com