当鼠标悬停和值来自自动完成函数时,我想要一个锚标记的值。我有一个添加的代码,但它没有给我一个锚标记的值。所以如何在鼠标悬停时获取锚标记的值 所以请帮帮我 谢谢你的进步
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
SearchText();
});
function SearchText() {
$("#txtSearch").autocomplete({
source: function (request, response) {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "Test.aspx/GetAutoCompleteData",
data: "{'username':'" + extractLast(request.term) + "'}",
dataType: "json",
success: function (data) {
response(data.d);
$(".ui-autocomplete").addClass("test1");
},
error: function (result) {
alert("Error");
}
});
},
focus: function () {
// prevent value inserted on focus
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;
}
});
$("#txtSearch").bind("keydown", function (event) {
if (event.keyCode === $.ui.keyCode.TAB &&
$(this).data("autocomplete").menu.active) {
event.preventDefault();
}
})
$(function () {
$(".ui-autocomplete li").hover(function () {
var txt = $(this).find('a').html(); // .text(); to get the text in anchors
alert(txt);
});
});
function split(val) {
return val.split(/,\s*/);
}
function extractLast(term) {
return split(term).pop();
}
$(function () {
$(".ui-autocomplete li").hover(function () {
var txt = $(this).find('a').html(); // .text(); to get the text in anchors
alert(txt);
});
});
}
</script>
HTML
<ul class="ui-autocomplete ui-menu ui-widget ui-widget-content ui-corner-all test1" role="listbox" aria-activedescendant="ui-active-menuitem" style="z-index: 1;
top: -16px; left: 115px; display: none; position: relative; width: 1310px;">
<li class="ui-menu-item" role="menuitem"><a class="ui-corner-all" tabindex="-1">City
Name</a></li>
<li class="ui-menu-item" role="menuitem">
<a class="ui-corner-all" tabindex="-1">
<br>
</a>
</li>
<li class="ui-menu-item" role="menuitem"><a class="ui-corner-all" tabindex="-1">Agra</a></li>
<li class="ui-menu-item" role="menuitem"><a class="ui-corner-all" tabindex="-1">Ahmedabad</a></li>
<li class="ui-menu-item" role="menuitem">
<a class="ui-corner-all" tabindex="-1">
<br>
</a>
</li>
<li class="ui-menu-item" role="menuitem"><a class="ui-corner-all" tabindex="-1">Location
Name</a></li>
<li class="ui-menu-item" role="menuitem">
<a class="ui-corner-all" tabindex="-1">
<br>
</a>
</li>
</ul>