cpp*_*pit 196 javascript url jquery url-fragment
例:
www.site.com/index.php#hello
Run Code Online (Sandbox Code Playgroud)
使用jQuery,我想将值hello
放在变量中:
var type = …
Run Code Online (Sandbox Code Playgroud)
Mus*_*usa 563
不需要jQuery
var type = window.location.hash.substr(1);
Run Code Online (Sandbox Code Playgroud)
Ahs*_*hid 35
您可以使用以下代码来完成:
var url = "www.site.com/index.php#hello";
var hash = url.substring(url.indexOf('#')+1);
alert(hash);
Run Code Online (Sandbox Code Playgroud)
Tal*_*lha 12
var url ='www.site.com/index.php#hello';
var type = url.split('#');
var hash = '';
if(type.length > 1)
hash = type[1];
alert(hash);
Run Code Online (Sandbox Code Playgroud)
关于jsfiddle的工作演示
这很容易。试试下面的代码
$(document).ready(function(){
var hashValue = location.hash.replace(/^#/, '');
//do something with the value here
});
Run Code Online (Sandbox Code Playgroud)
小智 6
使用以下JavaScript从URL获取散列(#)后的值.你不需要使用jQuery.
var hash = location.hash.substr(1);
Run Code Online (Sandbox Code Playgroud)
我从这里获得了这个代码和教程 - 如何使用JavaScript从URL获取哈希值
我有运行时的URL,下面给出了正确的答案:
let url = "www.site.com/index.php#hello";
alert(url.split('#')[1]);
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助
归档时间: |
|
查看次数: |
170886 次 |
最近记录: |