Javascript 如何在按钮单击事件上重定向页面

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14766940/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-24 17:50:24  来源:igfitidea点击:

How to redirect page on button click event

javascript

提问by David Van Staden

I am using a button on my form. How do I link to another web page/file when clicking on that link? Here is the code I tried, but does not work.

我正在使用表单上的按钮。单击该链接时如何链接到另一个网页/文件?这是我尝试过的代码,但不起作用。

<button class="btn" data-bind="click: function() { document.location.href=$(this).attr('RiskAssessmentMain.aspx'); }">back</button>

回答by Ahmet Kak?c?

<input type='button'value='back' class="btn" onclick="document.location.href='RiskAssessmentMain.aspx';"/>

Try it: http://jsfiddle.net/wzy4B/

试试看:http: //jsfiddle.net/wzy4B/

回答by ?т?

set the url you want to go in <form>actionattribute. then use a submitinstead of button.
Here is an example.:

<form>action属性中设置您要访问的 url 。然后使用 asubmit代替button.
这是一个例子。:

 <form action="http://google.com">   
    <input type="submit" value="Google">
 </form>

回答by ScoRpion

You Can try this one

你可以试试这个

<script>
      function open_win() {
           window.open("http://www.google.com")
      }
</script>

Or you can also Do it like this

或者你也可以这样做

<script>
       function openWin() {
            myWindow=window.open('','','width=200,height=100');
            myWindow.document.write("<p>This is 'myWindow'</p>");
            myWindow.focus();
       }
</script>

<input type="button" value="Open window" onclick="openWin()" />

回答by ScoRpion

Try this

尝试这个

  <nav>
    <ul>
      <li><a href="#">button</a></li>
    </ul>
  </nav>

and this the css

这是 css

nav
{
    position:fixed;
    bottom:350px;
    left:600px;
}

nav ul ul {
    display: none;
}

nav ul li:hover > ul {
    display: block;
}

nav ul {
    background: #FFD700; 
    box-shadow: 0px 0px 9px rgba(0,0,0,0.15);
    padding: 0 20px;
    border-radius: 10px;  
    list-style: none;
    position: relative;
    display: inline-table;
    color:black;
}

nav ul:after {
    content: ""; clear: both; display: block;
}

nav ul li {
    float: left;
}

nav ul li:hover {
    background:     #FFD700;
    color:white;
}

nav ul li:hover a {
    color:black;
}

nav ul li a {
    display: block; padding: 25px 40px;
    color: maroon; text-decoration: none;
}

nav ul ul {
    background:     #CFB53B;border-radius: 0px; padding: 0;
    position: absolute; top: 100%;
}

nav ul ul li {
    float: none; 
    border-top: 1px solid #6b727c;
    border-bottom: 1px solid #575f6a;
    position: relative;
}

nav ul ul li a {
    padding: 15px 40px;
    color: #fff;
}   
nav ul ul li a:hover {
    background: #996515;
}