Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在url中#-jquery/javascript之后查找姓氏_Javascript_Jquery - Fatal编程技术网

在url中#-jquery/javascript之后查找姓氏

在url中#-jquery/javascript之后查找姓氏,javascript,jquery,Javascript,Jquery,在jquery/javascript的url中,有没有一种方法可以获取#之后的姓氏 我想找到名字#价格 做一个假设陈述 if( the_last_name == 'prices' ) // do something 我需要js/jquery找到一种获取URL姓氏的方法(并在if station/the_last_name上进行检查)使用以下方法: document.location.hash 例如: 更好的方法是使用以下命令: if (document.location.hash.subs

在jquery/javascript的url中,有没有一种方法可以获取#之后的姓氏

我想找到名字#价格 做一个假设陈述

if( the_last_name == 'prices' ) 
// do something
我需要js/jquery找到一种获取URL姓氏的方法(并在if station/the_last_name上进行检查)

使用以下方法:

document.location.hash
例如:

更好的方法是使用以下命令:

if (document.location.hash.substr(1) == "prices") {
因此字符串中没有“#”号。

为什么不使用另一种方式,这样代码中就没有
.substr(1)
?1个额外字符对10个。
if (document.location.hash.substr(1) == "prices") {