Javascript 引导按钮 onclick 和 location.href

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25778744/
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-22 21:51:58  来源:igfitidea点击:

bootstrap button onclick and location.href

javascripttwitter-bootstrapbutton

提问by Macness

Any reason why this wouldn't work?

任何原因这不起作用?

<button class="btn btn-primary btn-lg" onClick="location.href='http://anothersitehere.com/file.pdf'">Download PDF</button>

采纳答案by yowza

It's seems that it is working regarding on going to the link. I'm using Chrome btw.

似乎它正在处理链接。顺便说一句,我正在使用 Chrome。

回答by Md. Salahuddin

You would try with this instead

你可以试试这个

<a class="btn btn-primary btn-lg" href="http://anothersitehere.com/file.pdf">
   Download PDF
</a>

回答by ashish lalwani

Leaving location.hrefblank and in javascript function give

留下location.href空白,并在javascript函数给予

document.location.href='page.php?variable='+value;

it will redirect to the page you want.

它将重定向到您想要的页面。