在百度中输入“测试”搜索,IE地址框中的URL代码为:http://www.baidu.com/s?cl=3&wd=%B2%E2%CA%D4
可见“测试”的编码是“B2%E2%CA%D4”。
google等其他搜索引擎的URL的编码与百度都一样,“测试”两字的编码都是“B2%E2%CA%D4”。
请问,如果我要写程序,怎么实现把“测试”转换为“B2%E2%CA%D4”。其他关键字类同,谢谢!

解决方案 »

  1.   

    http://community.csdn.net/Expert/topic/4260/4260416.xml?temp=.116604怎么这两天老有人问这个呢
      

  2.   

    GoogleSearchfunction SearchGoogle(obj,evt)
    {
    if (obj.tagName == "INPUT")
    {
    if(evt.keyCode==13 || evt.keyCode==0)
    {
    var keystr = encodeURIComponent(obj.value.trim());
    url ="http://www.google.com/custom?domains=chjl.cn&q="
    url += keystr +  "&sitesearch=chjl.cn&client=pub-6474687331285859&forid=1&ie=UTF-8&oe=GB2312&cof=GALT%3A%23008000%3BGL%3A1%3BDIV%3A%23336699%3BVLC%3A663399%3BAH%3Acenter%3BBGC%3AFFFFFF%3BLBGC%3A336699%3BALC%3A0000FF%3BLC%3A0000FF%3BT%3A000000%3BGFNT%3A0000FF%3BGIMP%3A0000FF%3BFORID%3A1%3B&hl=zh-CN";

    window.location=url;
    return;
    }
    }
    else if (obj.tagName == "A")
    {
    var keystr = encodeURIComponent(obj.innerText.trim());
    url ="http://www.google.com/custom?domains=chjl.cn&q="
    url += keystr + "&sa=%CB%D1%CB%F7&sitesearch=&client=pub-6474687331285859&forid=1&ie=UTF-8&oe=GB2312&cof=GALT%3A%23008000%3BGL%3A1%3BDIV%3A%23336699%3BVLC%3A663399%3BAH%3Acenter%3BBGC%3AFFFFFF%3BLBGC%3A336699%3BALC%3A0000FF%3BLC%3A0000FF%3BT%3A000000%3BGFNT%3A0000FF%3BGIMP%3A0000FF%3BFORID%3A1%3B&hl=zh-CN";
    window.location=url;
    return;
    }
    }演示 http://chjl.cn/Article/Read.aspx?ArticleID=755 关键字和相关文章一栏
      

  3.   

    同上
    Server.UrlEncode()
    Server.UrlDecode()
    配套使用