如何用HTML写一个浏览器!!!
制作可以选择搜索引擎的浏览器
先写一个form表单,初始action为“http://www.baidu.com/baidu”,引用一个文本框输入搜索内容。
利用select标签来选择搜索引擎。代码如下!!!
360的action为"https://www.so.com/s"。
<form action="http://www.baidu.com/baidu" id="form" target="_black">
<input type="text" name=word id="text">
<input type="submit" value="提交" onclick="a()">
<select name="" id="check">
<option value="百度" >百度</option>
<option value="360">360</option>
</select>
</form>
接下来写Javascript
function a(){
var i=document.getElementById("form").action;
var a=document.getElementById("check").value;
if(a=="百度"){
document.getElementById("form").action="http://www.baidu.com/baidu";
var list = document.getElementsByTagName("input");
list[0].name='word';
}
else{
document.getElementById("form").action="https://www.so.com/s";
var list = document.getElementsByTagName("input");
list[0].name='q';
}
}
注意!!
通过Javascript,使用如下代码改变form表单的action document.getElementById(“form”).action=“http://www.baidu.com/baidu”;
百度的搜索和360搜索有所不同。
在form表单中,百度的name为word,而360的为q。
要改变name的值,可以使用如下代码。
var list = document.getElementsByTagName(“input”);
list[0].name=‘q’;
先获得所有的input标签,形成一个list,再改变第一个元素的name。