JavaScript: Get anchor from URL JavaScript: Получить якорь, с URL
Posted on 10. Опубликованный 10. Jun, 2009 by Dragos in Apps , Coding , JavaScript & Ajax , PHP Июн, 2009 Dragos в Службе, кодирование, JavaScript & Ajax, 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 URL = '# комментарий http://iwebdevel.com/some-post-1'; / / если вы хотите взять текущий URL из окна использовать: VAR URL = window.location; var anchor=url.hash; //anchor with the # character VAR = Якорь url.hash / / якорь с символа # var anchor2=url.hash.substring(1); //anchor without the # character VAR 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 ( "хэш"); Related posts: Похожие сообщения:
- JavaScript: How to get the index (position within a group) of an object with jQuery? JavaScript: Как получить индекс (позиция в группе) объекта с JQuery?
- Javascript: How to validate email address with JavaScript? JavaScript: Как проверить адрес электронной почты с JavaScript?
- JavaScript: Send function as a parameter to another function (callbacks) JavaScript: Отправить функцию в качестве параметра в другую функцию (функции обратного вызова)
- JavaScript: What if jQuery animation doesn't fire/start? JavaScript: Что делать, если Jquery анимация не срабатывает / начать?
- JavaScript: Where do I Find All Properties for All HTML Elements ? JavaScript: Где мне найти свойства для всех элементов HTML?












































