页面:
报废申请人:<asp:TextBox ID="txtPUSER" runat="server" Width="70px" CssClass="txt"></asp:TextBox>
<div style="display:none ;width:95px;z-index:1000;position:absolute;background-color:#33CCCC; height:200px;overflow:scroll;" id="DivApplyPerson">
</div>
相应的js:
function getUserList() {
var top = $('#txtPUSER').offset().top;
top += 20;
var left = $('#txtPUSER').offset().left;
var name = $('#txtPUSER').val();
var ksListAll = null;
$.ajax({
type: "post",
async: false,
dataType: 'json',
url: '../Ajax/Locker.ashx',
data: { active: "getUser", Name: escape(name) },
success: function(json) {
ksListAll = json.list;
}
});
$('#DivApplyPerson').css("top", top);
$('#DivApplyPerson').css("left", left);
$('#DivApplyPerson').css("display", "block");
var strHTML = "";
if (ksListAll != null) {
$.each(ksListAll, function(i, item) {
strHTML = strHTML + "<a href='#' οnclick='getVal(this)' value='" + item.DEPTID + "' style=' width:100px; float:left'>" + item.FULLNAME + "</a>"
});
}
$("#DivApplyPerson").html(strHTML);
}
$('#txtPUSER').focus(function() {
getUserList();
}).keyup(function() {
getUserList();
});
function getVal(a) {
$("#txtPUSER").val(a.innerText);
$('#DivApplyPerson').css("display", "none");
}
$("#txtPUSER").blur(function() {
if (document.activeElement.parentElement != null) {
if (document.activeElement.parentElement.id != "DivApplyPerson") {
$('#DivApplyPerson').css("display", "none");
}
}
});