复制代码 代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script language="javascript" type="text/javascript">
function abc() {
var inputV = document.getElementById("in").value;
//根据浏览器判断
if (/msie/i.test(navigator.userAgent)) //ie浏览器
{
document.getElementById("lbltext").innerText = inputV;
}
else {//非ie浏览器,比如Firefox
document.getElementById("lbltext").innerHTML = inputV; //火狐等浏览器的赋值方式
}
}
function InputT() {
var f = document.getElementById("inpContent");
var abc = document.getElementById("btnHelp");
document.getElementById("btnHelp").click(); //触发Button的onclick事件
}
//为input 添加的keydown事件
function InputKeyDownFocus() {
//方向键的ASCII值:上:38,下:40
if (event.keyCode == "38" || event.keyCode == "40") {
document.getElementById("lst").focus(); //使ListBox获得焦点
}
else {
document.getElementById("inpContent").focus();
}
}
</script>
</head>
<body>
<form runat="server">
<div>
输入内容:
<br />
<input runat="server" oninput="InputT()" onpropertychange="InputT()"
onkeyup="InputKeyDownFocus()" </br> />
<asp:ListBox runat="server" OnSelectedIndexChanged="lst_SelectedIndexChanged"
AutoPostBack="true"</asp:ListBox>
<asp:Button runat="server" Text="隐藏按钮" />
</div>
</form>
</body>
</html>
复制代码 代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
enum Direction
{
Up, Right, Down, Left
}
Direction dir;
protected void Page_Load(object sender, EventArgs e)
{
btnHelp.Style.Add("display", "none");
}
protected void lstShow_SelectedIndexChanged(object sender, EventArgs e)
{
ListBox lItem = (ListBox)sender;
string lItemValue = lItem.SelectedItem.Text;
txtInput.Text = lItemValue;
}
/// summary
/// 前台调用的方法
/// /summary
/// param/param
/// param/param
protected void btnHelp_Click(object sender, EventArgs e)
{
string inputStr = inpContent.Value.Trim(); //文本框输入系统
Listobject listNew = new Listobject();
listNew.Add("abc");
listNew.Add("abcde");
listNew.Add("bcd");
listNew.Add("bcdef");
listNew.Add("bcdagb");
listNew.Add("bbccaa");
listNew.Add("aabbdd");
listNew.Add("ccaabbdd");
lst.Items.Clear(); //清除原有值
int i = 1;
foreach (object obj in listNew)
{
//符合条件的数据
if (obj.ToString().Contains(inputStr))
{
lst.Style.Add("display", "block");
lst.Items.Add(new ListItem(obj.ToString(), "" + i));
i++;
}
}
if (lst.Items.Count 0)
{
lst.SelectedIndex = 0;
}
inpContent.Focus();
}
/// summary
/// ListBox下拉框的值改变时
/// /summary
/// param/param
/// param/param
protected void lst_SelectedIndexChanged(object sender, EventArgs e)
{
ListBox lItem = (ListBox)sender;
lst.Style.Add("display", "block");
string lItemValue = lItem.SelectedItem.Text;
inpContent.Value = lItemValue;
lst.Focus();
}
新闻热点
疑难解答
图片精选