Javascript如何实现表单url传递?

来源:百度知道 编辑:UC知道 时间:2024/09/24 04:07:11
根目录index.html文件里,表单里面有一个文本域一个按钮,要求文本域输入字符提交后转到相应字符页面
如:文本域输入“123”,点击按钮,立刻转向localhost/123.html
注:这个就像PHP里面header()函数实现的url传递一样,要求是一个效果,但做出来必须是静态页面(javascript)
会的请直接上完整代码通过即给分,但是请别只写location那样的就一句话~
那种不懂的还随便复制粘贴的勿扰

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<script>
function forward(){
var local = document.getElementById("local").value;
if(local.length > 0) {
var formObj = document.getElementById("thisForm");
formObj.action = local;
formObj.target = "_self";
formObj.submit();
}
}
</script>
</HEAD>
<BODY>
<form id="thisForm">
<input type="text" id="local" value=""/>
</br>
<input type="button" value="测试" onclick="forward();"/>
</form>
</BODY>
</HTML>

<body>
<form name=form1 method=post>
<input type=text name="target" id="ta