我有一个表格,其中每一行都有一个带有自动填充功能的文本框。在服务器代码中它看起来像
<td><asp:TextBox ID="tbNumber" runat="server" onfocus="AttachNumbers(this)" /></td>
在客户端
function AttachNumbers(sender) {
$(sender).autocomplete({ source: GetNumbers, minLength: 2 });
}
function GetNumbers(request, response) {
$.ajax({
type: "POST",
url: AJAXSERVICEMETHOD,
data: "{ 'term': '" + request.term + "', 'count': 10 }",
contentType: "application/json; charset=utf-8",
dataType: "json",
success:
function(data, textStatus, jqXHR) {
response(data.d);
//HighlightError(HOW TO GET CONTROL HERE?);
},
error:
function(jqXHR, textStatus, errorThrown) {
}
});
}
如果用户没有从列表中选择数字(使用我有HighlightError(controlid)
的功能),我需要突出显示文本框。如何执行此操作?
答案 0 :(得分:1)
您可以使用jQuery.proxy将sender
传递给GetNumbers
函数作为上下文:
function AttachNumbers(sender) {
var sourceProxy = $.proxy(GetNumbers, sender);
$(sender).autocomplete({ source: sourceProxy, minLength: 2 });
}
function GetNumbers(request, response) {
var target = this;
$.ajax({
type: "POST",
url: AJAXSERVICEMETHOD,
data: "{ 'term': '" + request.term + "', 'count': 10 }",
contentType: "application/json; charset=utf-8",
dataType: "json",
success:
function(data, textStatus, jqXHR) {
response(data.d);
// target refers to sender control
//HighlightError(HOW TO GET CONTROL HERE?);
},
error:
function(jqXHR, textStatus, errorThrown) {
}
});
}