文本框自动提示功能

文本框自动提示功能文本框自动提示功能(有不明白的地方请留言)前置代码:              //JScript文?件t       //作Á¡Â者?:êo李¤?军¨¹       //输º?入¨?工¡è程¨¬名?称?时º¡À弹Ì¡¥出?提¬¨¢示º?       varintIndex=0;arrList=newArray();

文本框自动提示功能 

文本框自动提示功能(有不明白的地方请留言)

前置代码:

<%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”Default2.aspx.cs” Inherits=”Default2″ %>

<!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”>

        // JScript 文?件t

        //作Á¡Â者?:êo李¤?军¨¹

        //输º?入¨?工¡è程¨¬名?称?时º¡À弹Ì¡¥出?提¬¨¢示º?

        var intIndex = 0; arrList = new Array();

        function dearray(aa)//定¡§义°?array

        {

            arrList = aa.split(‘€’);

            intIndex = arrList.length;

        }

        function projectNameTip(projectName) {

            init();

            dearray(projectName);

            smanPromptList(arrList, “txtReservoirWater”); //txtReservoirWater代䨲表À¨ª你?要°a显?示º?提¬¨¢示º?内¨²容¨Y的Ì?文?本À?框¨°

        }

        function tablestyle() {

            var reservoirwater = “<%=GetReservoirwater() %>”;

            projectNameTip(reservoirwater);  //水?库a水?位?值¦Ì自Á?动¡¥匹£¤配?

        }

        function init() {

            if (arrList.constructor != Array) { alert(‘smanPromptList初?始º?化¡¥失º¡ì败㨹:第̨²一°?个?参?数ºy非¤?数ºy组Á¨¦!’); return; }

            arrList.sort(function (a, b) {

                if (a.length > b.length) return 1;

                else if (a.length == b.length) return a.localeCompare(b);

                else return -1;

            }

    );

        }

        function smanPromptList(arrList, objInputId) {

            var objouter = document.getElementById(“__smanDisp”) //显?示º?的Ì?DIV对?象¨®

            var objInput = document.getElementById(objInputId); //文?本À?框¨°对?象¨®

            var selectedIndex = -1;

            var intTmp; //循-环¡¤用®?的Ì?:)

            if (objInput == null) { alert(‘smanPromptList初?始º?化¡¥失º¡ì败㨹:没?有®D找¨°到Ì?”‘ + objInputId + ‘”文?本À?框¨°’); return; }

            //文?本À?框¨°失º¡ì去¨£¤焦1点Ì?

            objInput.onblur = function () {

                objouter.style.display = ‘none’;

            }

            //文?本À?框¨°按ã¡ä键¨¹抬¬¡ì起e

            objInput.onkeyup = checkKeyCode;

            //文?本À?框¨°得Ì?到Ì?焦1点Ì?

            objInput.onfocus = checkAndShow;

            function checkKeyCode(evt) {

                evt = evt || window.event;

                var ie = (document.all) ? true : false

                if (ie) {

                    var keyCode = evt.keyCode

                    if (keyCode == 40 || keyCode == 38) { //下?上¦?

                        var isUp = false

                        if (keyCode == 40) isUp = true;

                        chageSelection(isUp)

                    } else if (keyCode == 13) {//回?车¦Ì

                        outSelection(selectedIndex);

                    } else {

                        checkAndShow(evt)

                    }

                } else {

                    checkAndShow(evt)

                }

                divPosition(evt)

            }

            function checkAndShow(evt) {

                var strInput = objInput.value

                if (strInput != “”) {

                    divPosition(evt);

                    selectedIndex = -1;

                    objouter.innerHTML = “”;

                    for (intTmp = 0; intTmp < arrList.length; intTmp++) {

                        if (arrList[intTmp].substr(0, strInput.length).toLowerCase() == strInput.toLowerCase()) {

                            addOption(arrList[intTmp]);

                        }

                    }

                    objouter.style.display = ”;

                } else {

                    objouter.style.display = ‘none’;

                }

                function addOption(value) {

                    objouter.innerHTML += “<div οnmοuseοver=\”this.className=’sman_selectedStyle’\” οnmοuseοut=\”this.className=”\” οnmοusedοwn=\”document.getElementById(‘” + objInputId + “‘).value='” + value + “‘\”>” + value + “</div>”

                }

            }

            function chageSelection(isUp) {

                if (objouter.style.display == ‘none’) {

                    objouter.style.display = ”;

                } else {

                    if (isUp)

                        selectedIndex++

                    else

                        selectedIndex–

                }

                var maxIndex = objouter.children.length – 1;

                if (selectedIndex < 0) { selectedIndex = 0 }

                if (selectedIndex > maxIndex) { selectedIndex = maxIndex }

                for (intTmp = 0; intTmp <= maxIndex; intTmp++) {

                    if (intTmp == selectedIndex) {

                        objouter.children[intTmp].className = “sman_selectedStyle”;

                    } else {

                        objouter.children[intTmp].className = “”;

                    }

                }

            }

            function outSelection(Index) {

                objInput.value = objouter.children[Index].innerText;

                objouter.style.display = ‘none’;

            }

            function divPosition(evt) {

                var left = 0;

                var top = 0;

                var e = objInput;

                while (e.offsetParent) {

                    left += e.offsetLeft + (e.currentStyle ? (parseInt(e.currentStyle.borderLeftWidth)).NaN0() : 0);

                    top += e.offsetTop + (e.currentStyle ? (parseInt(e.currentStyle.borderTopWidth)).NaN0() : 0);

                    e = e.offsetParent;

                }

                left += e.offsetLeft + (e.currentStyle ? (parseInt(e.currentStyle.borderLeftWidth)).NaN0() : 0);

                top += e.offsetTop + (e.currentStyle ? (parseInt(e.currentStyle.borderTopWidth)).NaN0() : 0);

 

                objouter.style.top = (top + objInput.clientHeight) + ‘px’;

                objouter.style.left = left + ‘px’;

                objouter.style.width = objInput.clientWidth;

            }

        }

        document.write(“<div id=’__smanDisp’ style=’position:absolute;display:none;background:#E8F7EB;border: 1px solid #CCCCCC;font-size:14px;cursor: default;’ onbulr> </div>”);

        document.write(“<style>.sman_selectedStyle{background-Color:#102681;color:#FFFFFF}</style>”);

        function getAbsoluteHeight(ob) {

            return ob.offsetHeight

        }

        function getAbsoluteWidth(ob) {

            return ob.offsetWidth

        }

        function getAbsoluteLeft(ob) {

            var mendingLeft = ob.offsetLeft;

            while (ob != null && ob.offsetParent != null && ob.offsetParent.tagName != “BODY”) {

                mendingLeft += ob.offsetParent.offsetLeft;

                mendingOb = ob.offsetParent;

            }

            return mendingLeft;

        }

        function getAbsoluteTop(ob) {

            var mendingTop = ob.offsetTop;

            while (ob != null && ob.offsetParent != null && ob.offsetParent.tagName != “BODY”) {

                mendingTop += ob.offsetParent.offsetTop;

                ob = ob.offsetParent;

            }

            return mendingTop;

        }

        Number.prototype.NaN0 = function () {

            return isNaN(this) ? 0 : this;

        } 

    </script>

</head>

<body οnlοad=”tablestyle()”>

    <form id=”form1″ runat=”server”>

    <div>

       <td valign=”bottom” style=”width: 240px;”>

                                自Á?动¡¥显?示º?值¦Ì:êo<asp:TextBox ID=”txtReservoirWater”  onKeyUp=”clearNoNum(event,this)” onBlur=”checkNum(this)”

                                    runat=”server”></asp:TextBox>

                            </td>

    </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;

using System.Data;

 

public partial class Default2 : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    { 

    } 

    public string GetReservoirwater()

    {

        string reservoirwater = string.Empty;

        DataTable dt = new DataTable();

        dt.Columns.Add(“RESERVOIRWATER”,typeof(string));

 

        DataRow dr = dt.NewRow();

        dr[“RESERVOIRWATER”]=”1″;

        dt.Rows.Add(dr);

 

        DataRow dr1 = dt.NewRow();

        dr1[“RESERVOIRWATER”] = “1”;

        dt.Rows.Add(dr1);

 

        DataRow dr2 = dt.NewRow();

        dr2[“RESERVOIRWATER”] = “3”;

        dt.Rows.Add(dr2);

 

        DataRow dr3 = dt.NewRow();

        dr3[“RESERVOIRWATER”] = “4”;

        dt.Rows.Add(dr3);

 

        DataRow dr5 = dt.NewRow();

        dr5[“RESERVOIRWATER”] = “5”;

        dt.Rows.Add(dr5);

 

        DataRow dr6 = dt.NewRow();

        dr6[“RESERVOIRWATER”] = “5”;

        dt.Rows.Add(dr6); 

        for (int i = 0; i < dt.Rows.Count; i++)

        {

            reservoirwater = reservoirwater + dt.Rows[i][“RESERVOIRWATER”].ToString() + “€”;

        }

        return reservoirwater;

    }

}

 

去掉系统自带的提示,请看下一章。

今天的文章文本框自动提示功能分享到此就结束了,感谢您的阅读,如果确实帮到您,您可以动动手指转发给其他人。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/29443.html

(0)
编程小号编程小号

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注