HTML 和ASP用代码调用百度和谷歌来搜索文本框内的内容

 

<head>
    <title></title>
<script type="text/javascript">
    function openbd() {
      var s;

        var i = document.getElementById("text");
        var b = document.getElementById("radio");
        var b1 = document.getElementById("radio1");
        if (b.checked) {
        s= "http://www.baidu.com/s?wd=" + i.value;
    }
    else if (b1.checked) {
    s = "http://www.google.com/search?hl=en&newwindow=1&biw=1280&bih=843&q=" + i.value;
    }
              
        window.open(s, i.value, '')

   
   
   
    }

</script>
    <style type="text/css">
        #radio1
        {
            width: 26px;
        }
        #radio
        {
            width: 53px;
        }
    </style>
</head>
<body>
<form>
<input type="text" id="text" value="bai" />
<input type="button" value="搜索" οnclick="openbd()" />
<input type="radio" id="radio" value="1" name="radio" checked=checked />百度
<input type="radio" id="radio1"  value="2" name="radio"/>谷歌
</form>
</body>
</html>

 

 

用javascritp来作是相当的复杂,代码非常的多,当然用此来做有很多不同的方法,如果用Jquery,来做估计会更加的容易,因为它就是一个javascritp的类库,哈哈,说正题:我们用完了javascript,再来看一看用ASP.net 来做是怎么样的,不,应该说是用ASP.net 来做是多么简单的吧,哈哈请看下来这个些代码:

 

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class f1 : System.Web.UI.Page
{

    protected void Button1_Click1(object sender, EventArgs e)
    {
        if (RadioButton1.Checked)
        {
            Response.Redirect("http://www.baidu.com/s?wd=" + TextBox1.Text);
           
        }
        else
        {
            Response.Redirect("http://www.google.com/search?hl=en&newwindow=1&biw=1280&bih=843&q=" + TextBox1.Text);
        }
    }
 
}

 

 百度搜索的格式 http://www.baidu.com/s?wd=要搜索的文字(或内容)

 谷歌搜索的格式  http://www.google.com/search?hl=en&newwindow=1&biw=1280&bih=843&q=要搜索的文字(或内容)

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值