บทความนี้ส่วนใหญ่แนะนำ ASP เพื่อเลียนแบบสไตล์ Google แนะนำเพื่อให้ได้เอฟเฟกต์เมนูแบบเลื่อนลง
วันนี้ฉันจะใช้ ASP เพื่อเลียนแบบเมนูแบบเลื่อนลงของ Google แนะนำและอัปโหลดรหัสโดยตรง
1. รหัสเบื้องหน้า:
- <%@language = JavaScriptCodePage = 936%>
- <! doctypehtmlpublic-// w3c // dtdxhtml1.0transitional // en
- http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd>
- <htmlxmlns = http: //www.w3.org/1999/xhtml>
- <styleType = text/css>
- -
- .STYLE1 {สี:#FF0000}
- .MouseOut
- -
- ขนาดตัวอักษร: 12px;
- ความเป็นมา:#708090;
- สี: #fffafa;
- -
- .MouseOver
- -
- ขนาดตัวอักษร: 12px;
- ความเป็นมา: #FFFAFA;
- สี:#000000;
- -
- -
- </style>
- <scriptType = text/javascriptLanguage = JavaScript>
- varxmlhttp;
- Varcompletediv;
- VariInputfield;
- Varnametable;
- Varnametablebody;
- varflag = false;
- FunctionCreatexmlhttpRequest () {
- if (window.activexobject) {
- xmlhttp = newActivexobject (microsoft.xmlhttp);
- -
- elseif (window.xmlhttprequest) {
- xmlhttp = newxmlhttprequest ();
- -
- -
- functionsetFlag () {
- ธง = จริง;
- -
- functionDisselect ()
- -
- if (flag == false)
- document.getElementById (ป๊อปอัพ) .style.display = ไม่มี;
- -
- functionInitVars () {
- inputfield = document.getElementById (frmchangshang);
- nametable = document.getElementById (name_table);
- เสร็จสมบูรณ์ = document.getElementById (ป๊อปอัพ);
- nametablebody = document.getElementById (name_table_body);
- document.getElementById (ป๊อปอัพ) .style.display = บล็อก;
- -
- functionFindNames () {
- initvars ();
- if (inputfield.value.length> 0)
- -
- createxmlhttprequest ();
- varurl = search.asp? names =+inputfield.value;
- xmlhttp.open (รับ, url, true);
- xmlhttp.onreadystatechange = การโทรกลับ;
- XMLHTTP.SEND (NULL);
- -
- อื่น
- -
- Clearnames ();
- -
- -
- FunctionCallback () {
- if (xmlhttp.readystate == 4) {
- if (xmlhttp.status == 200)
- -
- พยายาม
- -
- varname = xmlhttp.responsexml.getElementsByTagname (ชื่อ)
- [0] .firstchild.data;
- -
- จับ (e)
- -
- document.getElementById (ป๊อปอัพ) .style.display = ไม่มี;
- Clearnames ();
- -
- setNames (xmlhttp.responsexml.getElementsByTagname (เนื้อหา));
- -
- elseif (xmlhttp.status == 204)
- -
- Clearnames ();
- -
- -
- -
- functionsetNames (The_names) {
- Clearnames ();
- varsize = the_names.length;
- setoffsets ();
- Varrow, Cell, Spans;
- สำหรับ (vari = 0; i <size; i ++) {
- //varnextnode=the_names [ฉันเหมือนกัน. firstchild.data;
- vare = the_names [i];
- // รับเนื้อหาโหนดลูกและโหลดลงในอาร์เรย์
- varnextNode = e.getElementByTagname (ชื่อ) [0] .firstchild.data;
- // สร้าง TR, TD, Span Elements
- row = document.createElement (TR);
- cell = 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 (เซลล์);
- nametablebody.appendchild (แถว);
- -
- -
- functionsetoffsets () {
- Varend = inputfield.offsetWidth;
- varleft = calculateOffsetLeft (inputfield);
- vartop = calculateOffSettop (inputfield)+inputfield.offSetheight;
- เสร็จสมบูรณ์ style.border = black1pxsolid;
- เสร็จสมบูรณ์ style.left = ซ้าย+px;
- เสร็จสิ้น style.top = top+px;
- nametable.style.width = 400px;
- -
- FunctionCalculateOffsetLeft (ฟิลด์) {
- returnCalculateOffset (ฟิลด์, Offsetleft);
- -
- FunctionCalculateOffSettop (ฟิลด์) {
- returnCalculateOffset (ฟิลด์, ออฟเซ็ตต์);
- -
- FunctionCalculateOffset (ฟิลด์, attr) {
- varoffset = 0;
- ในขณะที่ (ฟิลด์) {
- ออฟเซ็ต+= ฟิลด์ [attr];
- field = field.offsetParent;
- -
- returnoffset;
- -
- FunctionPopulatename (เซลล์) {
- // กรอกข้อมูลลงในหน้าเว็บ, เซลล์ ----> td object
- inputfield.value = cell.firstchild.nodevalue;
- Clearnames ();
- -
- // ล้างรายการอาร์เรย์
- functionclearNames () {
- varind = nametablebody.childnodes.length;
- สำหรับ (vari = ind-1; i> = 0; i-) {
- nametablebody.removechild (nametablebody.childnodes [i]);
- -
- เสร็จสมบูรณ์ style.border = ไม่มี;
- -
- </script>
- <head>
- <metahttp-equiv = content-typecontent = text/html; charset = gb2312/>
- <title> untitledDocument </title>
- </head>
- <body>
- <inputName = frMChangShangClass = inputTextId = frMChangShangStyle = ความกว้าง: 250px;
- onblur = disselect (); onkeyup = findNames (); size = 50MaxLength = 100>
- <spanclass = style1> เคล็ดลับ: ป้อนคำหลักและโปรแกรมจะจับคู่คุณโดยอัตโนมัติจากไลบรารี
- หากไม่มีการบันทึกให้เติมด้วยตัวเอง
- </span>
- <DivStyle = ตำแหน่ง: Absolute; Top: 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->
- -
- keyword = request.QueryString (ชื่อ)
- sql = selectlgid, lgmcfromgwherelgmclike '%& keyword &%' orderbylgiddesc
- setRs = server.createObject (adodb.recordset)
- Rs.opensql, Conn, 1,1
- Response.contentType = text/xml
- Response.write <? xmlversion = 1.0Encoding = GB2312?>
- Response.write <Surpase>
- dowhilenotrs.eof
- Response.write <SONTENT>
- response.write <name> & rs (LGMC) & </name>
- 'response.write <userId> & rs (userId) & </userId>
- 'response.write <Startime> & rs (startime) & </startime>
- 'response.write <DimTime> & rs (endtime) & </endtime>
- Response.write </stoment>
- Rs.Movenext
- วง
- Response.write </serponse>
- Rs.close
- setrs = ไม่มีอะไร
- -
ข้างต้นเป็นรหัสสำหรับ ASP เพื่อเลียนแบบสไตล์ Google แนะนำเพื่อให้ได้เอฟเฟกต์เมนูแบบเลื่อนลง