使用JS控制一个按钮跳到不同的页面

如何使用JS,控制按钮。比如 点击一个按钮。可能跳到A页面,也可能跳到B页面。也有可能退到C页面

这是按钮<a href="javascript:void(0)" onclick="gotopage">转到下一页</a><input type="text" id="page"/>

<script type="text/javascript">
function gotopage()
{
var Val=document.getElementById("page").value;
var Url="";
switch(Val)
{
case "1":Url="http://www.baidu.com";breck;
case "2":Url="http://www.google.com.hk";break;
}
window.open(Url);
}
</script>

这个的中心思想是能过不同变量确定要跳转的页面。再用window.open这个函数打开页面。
温馨提示:内容为网友见解,仅供参考
第1个回答  推荐于2018-04-12
需要有标记吧,不然程序怎么跳转?
var type=1;//标记
$('#button').click(function(){
var url='';
switch(type){
case 1:url='pageA.html';break;
case 2:url='pageB.html';break;
case 3:url='pageC.html';break;
}

location=url;
})本回答被提问者和网友采纳
相似回答