zoukankan      html  css  js  c++  java
  • 每日总结

    1.今天学习了AJAX 实时搜索

     if (str.length==0)
        { 
            document.getElementById("livesearch").innerHTML="";
            document.getElementById("livesearch").style.border="0px";
            return;
        }
        if (window.XMLHttpRequest)
        {// IE7+, Firefox, Chrome, Opera, Safari 浏览器执行
            xmlhttp=new XMLHttpRequest();
        }
        else
        {// IE6, IE5 浏览器执行
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange=function()
        {
            if (xmlhttp.readyState==4 && xmlhttp.status==200)
            {
                document.getElementById("livesearch").innerHTML=xmlhttp.responseText;
                document.getElementById("livesearch").style.border="1px solid #A5ACB2";
            }
        }
        xmlhttp.open("GET","livesearch.php?q="+str,true);
        xmlhttp.send();
    }


    $xmlDoc=new DOMDocument();
    $xmlDoc->load("links.xml");
    
    $x=$xmlDoc->getElementsByTagName('link');
    
    // 从 URL 中获取参数 q 的值
    $q=$_GET["q"];
    
    // 如果 q 参数存在则从 xml 文件中查找数据
    if (strlen($q)>0)
    {
        $hint="";
        for($i=0; $i<($x->length); $i++)
        {
            $y=$x->item($i)->getElementsByTagName('title');
            $z=$x->item($i)->getElementsByTagName('url');
            if ($y->item(0)->nodeType==1)
            {
                // 找到匹配搜索的链接
                if (stristr($y->item(0)->childNodes->item(0)->nodeValue,$q))
                {
                    if ($hint=="")
                    {
                        $hint="<a href='" . 
                        $z->item(0)->childNodes->item(0)->nodeValue . 
                        "' target='_blank'>" . 
                        $y->item(0)->childNodes->item(0)->nodeValue . "</a>";
                    }
                    else
                    {
                        $hint=$hint . "<br /><a href='" . 
                        $z->item(0)->childNodes->item(0)->nodeValue . 
                        "' target='_blank'>" . 
                        $y->item(0)->childNodes->item(0)->nodeValue . "</a>";
                    }
                }
            }
        }
    }
    
    // 如果没找到则返回 "no suggestion"
    if ($hint=="")
    {
        $response="no suggestion";
    }
    else
    {
        $response=$hint;
    }
    
    // 输出结果
    echo $response;
  • 相关阅读:
    Confluence无法打开编辑器,一直在转圈
    Xamarin.Forms中的ListView的ItemTrapped事件与ItemSelected事件的区别
    C#读取物理网卡信息及其对应的IP地址
    【Xamarin报错】visual studio android 模拟器部署卡住
    【Xamarin报错】AndroidManifest.xml : warning XA0101: @(Content) build action is not supported
    【Xamarin报错】 COMPILETODALVIK : UNEXPECTED TOP-LEVEL error java.lang.OutOfMemoryError: Java heap space
    【Xamarin报错】libpng warning : iCCP: Not recognizing known sRGB profile that has been edited
    子窗口调用父窗口
    Windows Phone 8.1 多媒体(3):音乐
    Windows Phone 8.1 多媒体(1):相片
  • 原文地址:https://www.cnblogs.com/chenghaixiang/p/14912387.html
Copyright © 2011-2022 走看看