ASP.NET: Custom AutoCompleteTextBox WebContro…

2008-02-22 09:32:45来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折


" return retMatches;\r\n",
" }\r\n",
"\r\n",
" function __DoAutoComplete(oEvent, id)\r\n",
" {\r\n",
" var oTextbox = document.getElementById(id '_textBox');\r\n",
" var frame = document.getElementById(id '_autoCompleteFrame');\r\n",
" var arrValues = document[id '_data'];\r\n",
" \r\n",
" switch (oEvent.keyCode) \r\n",
" {\r\n",
" case 38: //up arrow \r\n",
" case 40: //down arrow\r\n",
" case 37: //left arrow\r\n",
" case 39: //right arrow\r\n",
" case 33: //page up \r\n",
" case 34: //page down \r\n",
" case 36: //home \r\n",
" case 35: //end \r\n",
" case 13: //enter \r\n",
" case 9: //tab \r\n",
" case 27: //esc \r\n",
" case 16: //shift \r\n",
" case 17: //ctrl \r\n",
" case 18: //alt \r\n",
" case 20: //caps lock\r\n",
" case 8: //backspace \r\n",
" case 46: //delete\r\n",
" return true;\r\n",
" break;\r\n",
" \r\n",
" default:\r\n",
" textboxReplaceSelect(oTextbox, String.fromCharCode(isIE ? oEvent.keyCode : oEvent.charCode));\r\n",
" var iLen = oTextbox.value.length;\r\n",
"\r\n",
" var sMatches = autocompleteMatch(oTextbox.value, arrValues);\r\n",
"\r\n",
" if (sMatches.length > 0)\r\n",
" {\r\n",
" var arrMatches = sMatches.split(',');\r\n",
" oTextbox.value = arrMatches[0];\r\n",
" textboxSelect(oTextbox, iLen, oTextbox.value.length);\r\n",
" \r\n",
" if (arrMatches.length > 1)\r\n",
" {\r\n",
" frame.style.display = 'inline';\r\n",
" frame.height = '100';\r\n",
" \r\n",
" frame.contentWindow.document.body.innerHTML = '';\r\n",
" for (var i = 0; i < arrMatches.length; i )\r\n",
" {\r\n",
" frame.contentWindow.document.body.innerHTML = '<div style=\"width: 100%; cursor: default\" onmouseover=\"this.style.backgroundColor=\\'#316AC5\\'; this.style.color=\\'white\\';\" onmouseout=\"this.style.backgroundColor=\\'\\'; this.style.color=\\'black\\';\" onclick=\"parent.document.getElementById(\\'' id '_textBox\\').value = this.innerHTML\">' arrMatches[i] '</div>';\r\n",
" }\r\n",
" \r\n",
" frame.contentWindow.document.body.style.backgroundColor = 'white';\r\n",
" frame.contentWindow.document.onclick = function() { document.getElementById(id '_autoCompleteFrame').style.display = 'none'; };\r\n",
" } \r\n",
" } \r\n",
" \r\n",
" return false;\r\n",
" } \r\n",
" }\r\n",
"</script>\r\n",
"");
Page.ClientScript.RegisterClientScriptBlock(typeof(string), "__DoAutoComplete", script);
}

if (!Page.ClientScript.IsClientScriptBlockRegistered(MakeUniqueID("data")))
{
Page.ClientScript.RegisterClientScriptBlock(typeof(string), MakeUniqueID("data"), string.Format("<script language=\"javascript\" type=\"text/javascript\">document.{0}_data = {1}</script>", MakeUniqueID(null), ToJsStringArray(AutoCompleteData)));
}

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:ASP.NET小技巧:重写ViewState的存储目的地,以提高页面性能

下一篇:Asp.net把UTF-8编码转换为GB2312编码