この記事では、主にGoogleを模倣するスタイルを紹介して、それを参照することができます
今日、私はASPを使用してGoogleの提案スタイルドロップダウンメニューを模倣し、コードを直接アップロードします
1。前景コード:
- <%@言語= 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 {color:#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(){
- flag = true;
- }
- functiondisselect()
- {
- if(flag == false)
- document.getElementById(popup).style.display = none;
- }
- functionitvars(){
- 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 = callback;
- xmlhttp.send(null);
- }
- それ以外
- {
- ClearNames();
- }
- }
- functioncallback(){
- if(xmlhttp.readystate == 4){
- if(xmlhttp.status == 200)
- {
- 試す
- {
- varname = xmlhttp.responsexml.getelementsbytagname(name)
- [0] .firstchild.data;
- }
- キャッチ(e)
- {
- 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();
- Varrow、セル、スパン;
- for(vari = 0; i <size; i ++){
- //varnextnode = the_names [i] .firstchild.data;
- vare = the_names [i];
- //チャイルドノードのコンテンツを取得し、配列にリロードします
- varnextNode = e.getElementsByTagname(name)[0] .firstchild.data;
- // TR、TD、スパン要素を作成します
- 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(border、0);
- //cell.setattribute(onMouseover、setFlag());
- cell.onclick = function(){populatename(this);};
- // NextNodeをTDに追加します
- vartxtname = document.createTextNode(nextNode);
- Cell.AppendChild(txtname);
- //非表示データをスパン要素にロードします
- row.AppendChild(Cell);
- NameTableBody.AppendChild(row);
- }
- }
- functionsetoffsets(){
- varend = inputfield.offsetwidth;
- varleft = calculateOffsetLeft(inputfield);
- vartop = calculateOffsettop(inputfield)+inputfield.offseTheight;
- Completeiv.style.border = black1pxsolid;
- Completeiv.style.left = left+px;
- Completeiv.style.top = top+px;
- nameTable.style.width = 400px;
- }
- functionCalculateOffsetLeft(field){
- ReturnCalculateOffset(field、offsetLeft);
- }
- functionCalculateOffSettop(field){
- ReturnCalculateOffset(フィールド、オフセット);
- }
- functionCalculateOffset(field、attr){
- varoffset = 0;
- while(field){
- offset+= field [attr];
- field = field.offsetparent;
- }
- リターンオフセット;
- }
- functionpopulatename(cell){
- //データをWebページ、Cell ---> TDオブジェクトに入力します
- inputfield.value = cell.firstchild.nodevalue;
- ClearNames();
- }
- //リスト配列をクリアします
- functionclearnames(){
- varind = nametablebody.childnodes.length;
- for(vari = ind-1; i> = 0; i-){
- nameTableBody.RemoveChild(nametablebody.childnodes [i]);
- }
- Completeiv.style.border = none;
- }
- </script>
- <head>
- <metahttp-equiv = content-typecontent = text/html; charset = gb2312/>
- <title> untitleddocument </title>
- </head>
- <body>
- <inputname = frmchangshangclass = inputTextId = frmchangshangstyle = width:250px;
- onblur = disselect(); onkeyup = findnames(); size = 50maxlength = 100>
- <spanclass = style1>ヒント:キーワードを入力すると、プログラムはライブラリから自動的に一致します
- レコードが存在しない場合は、自分で記入してください
- </span>
- <divstyle = position:absolute; top:0; left: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(names)
- sql = selectlgid、lgmcfromwherelgmclike '%&keyword&%' orderbylgiddesc
- setrs = server.createObject(adodb.Recordset)
- rs.opensql、conn、1,1
- Response.ContentType = text/xml
- Response.Write <?xmlversion = 1.0Encoding = gb2312?>
- Response.Write <Response>
- dowhileenotrs.eof
- respons.write <content>
- respons.write <name>&rs(lgmc)&</name>
- 'Response.Write <UserID>&rs(userId)&</userId>
- 'Response.Write <Startime>&rs(startime)&</startime>
- 'Response.Write <EndTime>&rs(EndTime)&</EndTime>
- Response.Write </content>
- rs.movenext
- ループ
- Response.Write </response>
- rs.close
- setrs =何もない
- %>
上記は、ドロップダウンメニュー効果を実現するために、Googleの提案スタイルを模倣するためのコードです。