تقدم هذه المقالة بشكل أساسي ASP لتقليد Google اقتراحًا لتحقيق تأثير القائمة المنسدلة.
اليوم ، سوف أستخدم ASP لتقليد القائمة المنسدلة لـ Google اقتراح
1. رمز المقدمة:
- <٪@language = javaScriptCodePage = 936 ٪>
- <! doctypehtmlpublic-// w3c // dtdxhtml1.0transternal // en
- http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd>
- <htmlxmlns = http: //www.w3.org/1999/xhtml>
- <Tyletype = text/css>
- <!-
- .style1 {color:#ff0000}
- .houseout
- {
- حجم الخط: 12 بكسل ؛
- الخلفية:#708090 ؛
- اللون: #fffafa ؛
- }
- .mouseover
- {
- حجم الخط: 12 بكسل ؛
- الخلفية: #fffafa ؛
- اللون:#000000 ؛
- }
- ->
- </style>
- <scriptType = text/javaScriptLanguage = javaScript>
- varxmlhttp ؛
- varcompletediv.
- Variinputfield ؛
- varnametable
- varnametable ؛
- varflag = false ؛
- functionCreatexMlHttPrequest () {
- if (window.activexobject) {
- XMLHTTP = NewActivexObject (Microsoft.xmlHttp) ؛
- }
- elseif (window.xmlhttprequest) {
- xmlhttp = newxmlhttprequest () ؛
- }
- }
- functionSetFlag () {
- العلم = صحيح ؛
- }
- FunctionDissElect ()
- {
- إذا (العلم == خطأ)
- document.getElementById (popup) .style.display = none ؛
- }
- functionInitvars () {
- inputField = document.getElementById (frmchangshang) ؛
- nametable = document.getElementById (name_table) ؛
- completeiv = document.getElementById (popup) ؛
- nametablebody = document.getElementById (name_table_body) ؛
- document.getElementById (popup) .style.display = block ؛
- }
- FunctionFindNames () {
- initvars () ؛
- if (inputfield.value.length> 0)
- {
- createxmlHttprequest () ؛
- varurl = search.asp؟ names =+inputfield.value ؛
- xmlhttp.open (get ، url ، true) ؛
- XMLHTTP.OnReadyStateChange = رد الاتصال ؛
- xmlhttp.send (null) ؛
- }
- آخر
- {
- ClearNames () ؛
- }
- }
- functionCallback () {
- if (xmlhttp.readyState == 4) {
- if (xmlhttp.status == 200)
- {
- يحاول
- {
- varname = xmlhttp.responsexml.getElementsbyTagname (الاسم)
- [0] .firstchild.data ؛
- }
- الصيد (ه)
- {
- document.getElementById (popup) .style.display = none ؛
- ClearNames () ؛
- }
- setNames (xmlhttp.responsexml.getElementsByTagName (content)) ؛
- }
- elseif (xmlhttp.status == 204)
- {
- ClearNames () ؛
- }
- }
- }
- FunctionSetNames (the_names) {
- ClearNames () ؛
- varsize = the_names.length ؛
- setoffsets () ؛
- فارو ، الخلية ، يمتد.
- لـ (vari = 0 ؛ i <size ؛ i ++) {
- //varnextnode=the_names budapi.
- vare = the_names [i] ؛
- // احصل على محتوى العقدة الفرعية وأعيد تحميله في صفيف
- varnextNode =
- // إنشاء TR ، TD ، عناصر span
- الصف = document.createElement (tr) ؛
- الخلية = document.createElement (TD) ؛
- //spans=document.createElement(span) ؛
- // تعيين خصائص الخلية
- cell.onmouseout = function () {this.className = 'mouseover' ؛ flag = false ؛} ؛
- cell.onmouseover = function () {this.className = 'mouseout' ؛ flag = true ؛} ؛
- cell.setattribute (bgColor ،#fffafa) ؛
- cell.setattribute (الحدود ، 0) ؛
- //cell.setattribute (onMouseover ، setFlag ()) ؛
- cell.onclick = function () {populatename (this) ؛} ؛
- // أضف NextNode إلى TD
- vartxtName = document.createTextNode (nextNode) ؛
- cell.appendchild (txtName) ؛
- // تحميل البيانات المخفية إلى العنصر
- row.appendchild (Cell) ؛
- nametabledody.appendchild (row) ؛
- }
- }
- functionSetOffSets () {
- varend = inputField.OffSetWidth ؛
- varleft = calculateOffSetLeft (InputField) ؛
- vartop = calculateOffSetTop (inputfield)+inputfield.offsetheight ؛
- completev.style.border = Black1pxSolid ؛
- completev.style.left = left+px ؛
- completev.style.top = Top+px ؛
- nametable.style.width = 400px ؛
- }
- functionCalculateOffSetLeft (حقل) {
- ReturnCalculateOffset (الحقل ، OffsteLft) ؛
- }
- functionCalculateOffSettop (الحقل) {
- ReturnCalculateOffset (الحقل ، Offsettop) ؛
- }
- functionCalculateOffset (الحقل ، attr) {
- varoffset = 0 ؛
- بينما (الحقل) {
- الإزاحة+= الحقل [attr] ؛
- الحقل = field.OffSetParent ؛
- }
- مرجع الإرجاع
- }
- FunctionPopulatename (الخلية) {
- // املأ البيانات إلى صفحة الويب ، الخلية ----> كائن TD
- inputfield.value = cell.firstchild.nodevalue ؛
- ClearNames () ؛
- }
- // امسح صفيف القائمة
- FunctionClearNames () {
- varind = nametabledody.childnodes.length ؛
- لـ (vari = ind-1 ؛ i> = 0 ؛ i-) {
- nametablebody.removechild (nametablebody.childnodes [i]) ؛
- }
- completev.style.border = none ؛
- }
- </script>
- <head>
- <metahttp-equiv = content-typecontent = text/html ؛ charset = gb2312/>
- <title> UntitleDDocument </itlem>
- </head>
- <body>
- <inputName = frmChangShangClass = inputTextId = frmchangshangstyle = width: 250px ؛
- onblur = diselect () ؛ onKeyup = findNames () ؛ الحجم = 50maxLength = 100>
- <spanclass = style1> نصيحة: أدخل الكلمات الرئيسية وسيطابقك البرنامج تلقائيًا من المكتبة
- إذا لم يكن السجل موجودًا ، املأه بنفسك
- </span>
- <divstyle = الموضع: مطلق ؛ أعلى: 0 ؛ اليسار: 0 ؛ id = popup>
- <tableid = name_tablebgcolor =#fffafaborder = 0cellspacing = 0
- cellpadding = 0>
- <tbodyId = name_table_body> </tbody>
- </table>
- </div>
- </body>
- </html>
2.
ما عليك سوى تغيير عبارة SQL والحقول المراد عرضها على التنسيق المقابل لقاعدة البيانات الخاصة بك.
- <!-#includevirtual = conn.asp->
- <٪
- الكلمة الرئيسية = request.querystring (أسماء)
- SQL = SELECTLGID ، LGMCFROMGWHERELGMMCLIKE '٪ والكلمة الرئيسية و ٪' Orderbylgiddesc
- setRs = server.createBject (adodb.recordset)
- Rs.Opensql ، Conn ، 1،1
- استجابة. contenttype = text/xml
- استجابة. write <؟ xmlversion = 1.0encoding = gb2312؟>
- استجابة
- dowhilenotrs.eof
- استجابة
- Response.write <ame> & rs (LGMC) & </name>
- 'Response.write <Servid> & rs (userId) و </userD>
- 'response.write <startime> & rs (startime) & </startime>
- 'response.write < -endtime> & rs (Endtime) & </endtime>
- استجابة. write </content>
- Rs.Movenext
- حلقة
- استجابة. write </response>
- Rs.close
- setRs = لا شيء
- ٪>
ما سبق هو رمز ASP لتقليد أسلوب Google اقتراح لتحقيق تأثير القائمة المنسدلة.