我有一个文本框,我正在使用Ajax自动完成功能。
该函数工作正常,正在从数据库中获取值,并将值填充到TextBox中。
但是我有一个按钮,它触发一个查询并获取标签中的一些值。此查询使用所选的自动补全值来获取值。
当我尝试调试时,我发现使用的textbox值是空的,这导致了问题。所以我有可能,虽然Textbox的值是填充的,但是没有被设置。
下面是我的AJAX代码。
<link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
<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();
});
//data: "{'tagName':'" + document.getElementById('txtSearchDir').value + "'}", here tagName should be same to the variable name in fn
function SearchText() {
$("#txtSearchDir").autocomplete({
source: function (request, response) {
//alert('inside');
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "SearchPage.aspx/autoTagSearch",
data: "{'tagName':'" + document.getElementById('txtSearchDir').value + "'}",
dataType: "json",
success: function (data) {
response(data.d);
autoFocus: true
},
error: function (result) {
document.getElementById('txtSearchDir').value = "";
// alert(url);
},
});
}
});
}发布于 2015-09-21 14:40:59
一种方法是将选定的值保存到页面上的隐藏文本框中,以便即使在触发其他事件后也可以使用它。
您可以使用function autoCompleteItemSelected(source, eventArgs)事件来完成此操作。
(在网络上的某个地方有一篇我用过的老帖子,效果很好,但现在找不到了。)
您可以使用eventArgs.get_value();获取选定的值,然后设置隐藏的文本框。
https://stackoverflow.com/questions/32550548
复制相似问题