我有一个母版页,其中我有以下代码。
<head runat="server">
<link href="StyleSheet.css" rel="stylesheet" runat="server" type="text/css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js"></script>
<asp:contentplaceholder id="LocalScripts" runat="server"></asp:contentplaceholder>
</head>
<body id="body" runat="server">
<form id="form1" runat="server" defaultbutton="SignOutLB">
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</form>
</body>
我的内容页面包含以下代码。
<asp:Content ID="ScriptContent" ContentPlaceHolderID="localScripts" runat="server">
<script type="text/javascript">
function suggest(inputString)
{
if(inputString.length == 0)
{
$('#suggestions').fadeOut();
}
else
{
$('#AAATB').addClass('load');
$.post("AutoSuggest.aspx?ST=" + inputString, function(data){
if(data.length >0)
{
$('#suggestions').fadeIn();
$('#suggestionsList').html(data);
$('#AAATB').removeClass('load');
}
});
}
}
function fill(thisValue)
{
$('#AAATB').val(thisValue);
setTimeout("$('#suggestions').fadeOut();", 600);
}
</script>
</asp:Content>
ASP.NET代码如下。
<asp:TextBox ID="AAATB" runat="server" Width="90px" MaxLength="6" onkeypress="return IsNumberKey(event)" CssClass="textboxStyle" ValidationGroup="projNoValGp" onkeyup="suggest(this.value);" onblur="fill();" />
<div class="suggestionsBox" id="suggestions" style="display: none;">
<img src="Images/arrow.png" style="position: relative; top: -2px; left: 50px;" alt="" />
<div class="suggestionList" id="suggestionsList"> </div>
</div>
我的AutoSuggest.aspx有以下代码。(我已经完成了测试。一旦功能正常,我将更改此功能以从数据库中检索数据。)
protected void Page_Load(object sender, EventArgs e)
{
string[] arr = new string[] {
"1234",
"1111",
"1333",
};
for (int i = 0; i < 3; i++)
{
Response.Write("<li onClick=\"fill(\'" + arr[i] + "\');\">" + arr[i] + "</li>");
}
}
这可以达到显示值“1234”,“1111”,“1333”的程度。但是当我选择其中一个值时,它不会反映在文本框“AAATB”中。
对于解决这个问题的所有帮助,我将不胜感激。
谢谢, 卡罗来纳州
答案 0 :(得分:0)
我想我知道。您使用'#AATB'作为文本框的选择器。但是,这是一个服务器端ID,将在客户端上以不同方式呈现。 尝试使用此作为填充代码:
function fill(thisValue)
{
$('.textboxStyle').val(thisValue);
setTimeout("$('#suggestions').fadeOut();", 600);
}
这个想法是使用css-class作为文本框的选择器,因为它没有被修改。