عدم انتخاب گزینه های سرچ شده
سلام.
من دستور زیر رو برای auto complete با jquery نوشتم.
مشکلی که دارم اینه که وقتی یک بار سرچ می کنم و گزینه مدنظرم رو انتخاب مب کنم، اگه همون گزینه رو حذف کنم و مجدد سرچ کنم، دیگه اجازه انتخاب از بین گزینه هایی که سرچ کرده و آورده رو به من نمیده. هر چی روشون کلیک می کنم گزینه ای انتخاب نمیشه
ممنون میشم کمکم کنید
$(document).ready(function () {
$("#ProductNService").autocomplete(
{
autoFocus: true,
minLength: 3, // set minimum of 4 characters before search executes.
delay: 500, // wait 1 second after keystroke before search executes.
source: function (request, response) {
$.ajax({
url: '@Url.Action("GetJsonRecords", "ProductNService")',
type: "POST",
dataType: "json",
data: { term: request.term },
success: function (data) {
response($.map(data, function (item) {
return { label: item.Title, value: item.Title,id: item.Id};
}))
}
});
},
select: function (event, result) {
$("#ProductNServiceID").val(result.item.id);
//return;
}
});
})
نقل قول: عدم انتخاب گزینه های سرچ شده
من اینطوری ( شایدم غیر استفاندارد) استفاده میکنم :
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style>
.ui-autocomplete {
max-height: 200px;
overflow-y: auto; /* prevent horizontal scrollbar */
overflow-x: hidden;
}
/* IE 6 doesn't support max-height
* we use height instead, but this forces the menu to always be this tall
*/ * html .ui-autocomplete {
height: 200px;
}
.ui-textbox {
background: #DFEFFC url(chkpm/JS/themes/base/images/ui-bg_glass_85_dfeffc_1x400.png) 50% 50% repeat-x;
color: #2E6E9E;
border: 1px solid #C5DBEC;
padding: 5px;
border-radius: 5px;
font-family: Tahoma;
font-size: 11px;
}
.style1 {
height: 11px;
}
</style>
<script type="text/javascript" language="javascript">
var availableTagsM = [];
$.ajax({
type: "GET",
url: "Engineadmin.aspx",
data: "do=listMashin",
cache: false,
success: function (str) {
availableTagsM = str.split("@_@");
}
});
function autocompM(strtxtM) {
$("#" + strtxtM).autocomplete({
source: availableTagsM
});
}
</script>
</head>
<body>
<input type="text" id="ListM" class="ui-textbox" style="width: 150px;" autocomplete="false"
onkeydown="autocompM('ListM');" onkeyup="autocompM('ListM');" tabindex="1" />
</body>
</html>
کد رو هم اینطوری نوشتم :
Private Sub listMashin()
Dim Conn As New SqlConnection(ConfigurationManager.ConnectionStrin gs("ConnectionString").ConnectionString)
Conn.Open()
Dim CmdAdmin As New SqlCommand("select Name,shomare from Moshtari order by SN ", Conn)
Dim R As SqlDataReader = CmdAdmin.ExecuteReader
Dim strback As String = ""
While R.Read
strback += R("shomare").ToString + "@_@"
End While
CmdAdmin.Dispose()
R.Close()
Conn.Close()
Conn.Dispose()
Response.Write(strback)
End Sub