网页制作中,写表单里 填写上123456,提交后跳转baidu.com/123456.html 怎么写代码

如题。。昨天有人给我答案。了。。写上123456就会转到 baidu.com/123456.html ;但是我如果写的是654321并不会跳到baidu.com/654321.html
我需要的是输入什么东西就跑到baidu.com/输入的内容.html

以下是昨天帮助我的人提供的代码。

<input type="text" id="Sub" value="" />
<input type="button" onclick="Sub();" value="提交">
<script>
function Sub(){
var a=document.getElementById("Sub").value;
if(a=="123456"){
window.location.href = "http://zhidao.baidu.com/123456.html";
}
}
</script>

以上代码放入html页面中即可实现功能。

<input type="text" id="Sub" value="" />
<input type="button" onclick="Sub();" value="提交">
<script>
function Sub(){
var a=document.getElementById("Sub").value;
window.location.href = "http://zhidao.baidu.com/" + a + ".html";


</script>

温馨提示:答案为网友推荐,仅供参考