找到“#”使用Javascript的字符串中的字符 [英] Find the "#" character in a string with Javascript

查看:89
本文介绍了找到“#”使用Javascript的字符串中的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要通过Javascript解析给定的URL,但是我无法使用.split()来完成此任务。

I need to parse the given urls via Javascript but I'm not able to use .split() to accomplish to this.

IE:

  var str = window.location.pathname;
  var substr = str.split('/');
  alert(substr)

如果我输入此网址http://mydomain.com / myaddress / page / 2 /我有thoose值myaddress,page,2

If i enter this url "http://mydomain.com/myaddress/page/2/" I have thoose values "myaddress,page,2"

但如果代替/我插入#

But it doesn't work if instead of / I insert #

推荐答案

您正在寻找 的location.hash 。它包含本身及其后的所有内容。

You are looking for location.hash. It contains the # itself and everything that comes after it.

这篇关于找到“#”使用Javascript的字符串中的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆