【发布时间】:2013-03-27 03:46:00
【问题描述】:
使用这个插件 https://github.com/aehlke/tag-it 顺便说一句,它非常酷。
问题:
<input type="hidden" name="tags" id="mySingleField" value="Apple, Orange" disabled="true">
Tags:<br>
<ul id="mytags"></ul>
<script type="text/javascript">
$(document).ready(function () {
$("#mytags").tagit({
singleField: true,
singleFieldNode: $('#mySingleField'),
allowSpaces: true,
minLength: 2,
removeConfirmation: true,
tagSource: function (request, response) {
//console.log("1");
$.ajax({
url: "../City/GetList",
data: { term: request.term },
dataType: "json",
success: function (data) {
response($.map(data, function (item) {
return {
label: item.label + " (" + item.id + ")",
value: item.value
}
}));
}
});
}
});
});
</script>
当标签选择值时,它会将值添加到值 attr 中 CSV 格式的隐藏字段中。我想让它做 ID 而不是有人知道怎么做吗?
【问题讨论】:
-
请问你为什么要这样做
-
我想将 id 而不是值传回服务器
-
Line #238 of the plugin provided 是设置值的位置,如果有帮助的话。
标签: javascript jquery tag-it