This is a translated page. The original can be found here: http://iwebdevel.com/2009/06/10/javascript-get-anchor-from-url/
UPDATES VIA RSS | Email威盛最新的RSS | 电子邮件 Get updates via feedburner Get updates via twitter
Home / Apps / Coding / JavaScript & Ajax / PHP / JavaScript: Get anchor from … 首页 / 应用程序 / 编码 / JavaScript的与阿贾克斯 / PHP的 / JavaScript的:获取锚从...

JavaScript: Get anchor from URL JavaScript的:从网址锚

Posted on 10.发布10。 Jun, 2009 by Dragos in Apps , Coding , JavaScript & Ajax , PHP 2008年6月,2009年在企业应用编码与阿贾克斯的JavaScript,PHP 德拉戈什

To get the anchor from an URL (this is the text after the # character) in JavaScript you can use the following code:为了从一个URL锚(这是继#字符的文本在JavaScript),你可以使用下面的代码:

 var url='http://iwebdevel.com/some-post#comment-1'; //if you need to take the current url of the window use: var url=window.location; VAR的网址='http://iwebdevel.com/some-post#评论- 1'; / /如果你需要采取窗口的使用当前网址:VAR的网址= window.location;
var anchor=url.hash; //anchor with the # character VAR的锚= url.hash; / /以#字符锚
var anchor2=url.hash.substring(1); //anchor without the # character无功anchor2 = url.hash.substring(1); / /锚无#字符 

If you're iterating through the links in a page with JQuery, and $(this) defines a single link, then to find the anchor of this object you'd need to use the following code:如果您遍历在与JQuery的页面上的链接美元(这)定义了一个链接,然后找到该对象定位你需要使用下面的代码:

 var anchor=$(this).attr("hash"); VAR的锚= $(本)。的Attr(“散”); 
Translate this post翻译这个职位


Related posts:相关岗位:

  1. Javascript: How to validate email address with JavaScript? JavaScript的:如何用JavaScript验证电子邮件地址?
  2. JavaScript: How to get the index (position within a group) of an object with jQuery? JavaScript的:如何获取指数(位置在一组与jQuery对象)?
  3. JavaScript: Send function as a parameter to another function (callbacks) JavaScript的:寄另一个函数(回调参数功能)
  4. JavaScript: What if jQuery animation doesn't fire/start? JavaScript的:如果jQuery的动画不火/开始?
  5. JavaScript: GIFless animation. JavaScript的:GIFless动画。 Animate images,logos with jQuery 动画图像,标识与jQuery

    blog comments powered by Disqus 博客评论 Disqus