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="搜索" onclick="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=要搜索的文字(或内容)