<tr>
<td height="24" class="bline">
<table width="900" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="12%">
交易品种:
</td>
<td width="88%">
<input name="selectVariety" id="selectVariety" type="text" style="width:150px"
placeholder="输入品种名称进行添加"/>
<input name="selectVarietys" id="selectVarietys"
value="${exchange?if_exists.selectVarietys?if_exists}" type="hidden"
style="width:150px"/>
<#if reflist?exists && reflist?size > 0>
<#list reflist as pr>
<a href="javascript:deleteVariety('${(pr.exchangeVarietyId)!}');" class="xiaomai"
id="xiaomai${(pr.exchangeVarietyId)!}"><i></i>${(pr.varietyName)!}</a>
</#list>
</#if>
<span id="spefilelast"></span>
</td>
</tr>
</table>
</td>
</tr>
$(function () {
$("#selectVariety").autocomplete("${contextPath}/back/xianhuo/exchangeVariety/getVarietys.htm", {
minChars: 1,
max: 20,
matchContains: true,
autoFill: false,
matchSubset: false,
dataType: 'json',
extraParams: {
name: function () {
return $("#selectVariety").val();
}
},
parse: function (json) {
data = json.data;
return $.map(eval(data), function (row) {
return {
data: row,
value: row.id,
result: row.name
}
});
},
formatItem: function (data, i, n) {
return "<table width='100%' bgcolor='#CCE58B' ><tr ><td align='left' width='20%'>" + data.id + "</td><td align='left' >" + data.name + " </td></tr></table>";
},
formatResult: function (data, value) {
return data.name;
}
}).result(function (event, data, formatted) { //回调
var old = $('#selectVarietys').val();
//第一位判断不加前逗号
if (old.indexOf(data.id.toString() + ",") == 0) {
alert('该品种已存在!');
return;
}
//其他位置的加两个逗号
if (old.indexOf("," + data.id.toString() + ",") > -1) {
alert('该品种已存在!');
return;
}
$('#selectVarietys').val(old + data.id + ",");
var newVariety = '<a href="javascript:deleteVariety(' + data.id + ');" class="xiaomai" id="xiaomai' + data.id + '"><i></i>' + data.name + '</a>';
$("#spefilelast").before(newVariety);
});
});
function deleteVariety(id) {
var old = $('#selectVarietys').val();
old = old.replace(id + ",", "")
$('#selectVarietys').val(old);
$('#xiaomai' + id).remove();
}