javascript 如何在javascript中的问号后获取url值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22094081/
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-10-27 22:25:32 来源:igfitidea点击:
how to get url value after question mark in javascript
提问by user3364529
How can I get the url value after a question mark in javascript?
如何在javascript中的问号后获取url值?
I want the following behaviour:
我想要以下行为:
if value is yes then 10+2
else if value is no then 10.
I want to output with alert messages.
我想输出警报消息。
<div class="col-xs-4 col-sm-4 col-md-4 text-center width100">
<a href="piccal.html" class="btn btn-success" id="yes">PIC Grant Calculator</a>
</div>
<div class="col-xs-4 col-sm-4 col-md-4 text-center width100">
<a href="piccal.html" class="btn btn-danger" id="no">PIC Grant Calculator</a>
</div>
<script>
if (value == no) {
alert('hello');
}
</script>
<script>
if (value == yes) {
alert('hi');
}
</script>
回答by AO_
use javsacript and type:
使用 javsacript 并输入:
location.search
回答by kp singh
use this code:
使用此代码:
var a = location.href;
var b = a.substring(a.indexOf("?")+1);