0
在$.ajax({
中,我用標籤返回標籤,但我想在第一個標籤下面添加第二個標籤,我試過+ "\n" +
。更好的問題是我如何在那裏插入html
?因爲以後也許我想插入表或其他東西來好看。Ajax源代碼返回多個標籤。如何在第一個標籤後添加新行
下面是腳本:
<script type="text/javascript">
$(document).ready(function() {
function split(val) {
return val.split(/,\s*/);
}
function extractLast(term) {
return split(term).pop();
}
$("#search").autocomplete({
source: function (request, response) {
$.ajax({
url: "/Jobs/GetTags",
type: "POST",
dataType: "json",
data: { term: extractLast(request.term)},
success: function (data) {
response($.map(data, function (item) {
return {
label: item.Name + "\n" + item.Description,
value: item.Name,
};
}))
}
})
},
focus: function() {
return false;
},
search: function() {
// custom minLength
var term = extractLast(this.value);
if (term.length < 2) {
return false;
}
},
select: function (event, ui) {
var terms = split(this.value);
// remove the current input
terms.pop();
// add the selected item
terms.push(ui.item.value);
// add placeholder to get the comma-and-space at the end
terms.push("");
this.value = terms.join(", ");
return false;
},
messages: {
noResults: '',
results: function() { }
}
});
})
這裏是剃刀:
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
<p>
Tags @Html.TextBox("search")
</p>
}