JavaScript: Get anchor from URL JavaScript: Get enkuru no URL
Posted on 10. Posted on 10. Jun, 2009 by Dragos in Apps , Coding , JavaScript & Ajax , PHP Jun, 2009 by Dragos in Apps, kodēšana, JavaScript un Ajax, PHP
To get the anchor from an URL (this is the text after the # character) in JavaScript you can use the following code: Lai iegūtu enkurs no URL (tas ir pēc # rakstzīmju tekstu) in JavaScript varat izmantot šādu kodu:
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 # comment-1 "; / / ja Jums ir nepieciešams veikt pašreizējā URL loga izmantot: var url = window.location; var anchor=url.hash; //anchor with the # character var noenkuroties = url.hash; / / enkuru ar # raksturs var anchor2=url.hash.substring(1); //anchor without the # character var anchor2 = url.hash.substring (1); / / enkuru bez # raksturs
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: Ja jūs atkārtojot caur in lapu ar jquery saites un $ (this) nosaka vienu saiti, tad atrast enkuru par šo objektu vēlaties nepieciešams izmantot šādu kodu:
var anchor=$(this).attr("hash"); var enkurs = $ (this). attr ( "kapāta gaļa"); Related posts: Related posts:
- Javascript: How to validate email address with JavaScript? Javascript: Kā lai apstiprinātu e-pasta adresi ar JavaScript?
- JavaScript: How to get the index (position within a group) of an object with jQuery? JavaScript: Kā nokļūt indekss (amatu grupā) un objekts ar jQuery?
- JavaScript: Send function as a parameter to another function (callbacks) JavaScript: Sūtīt funkcija kā parametru citai funkcijai (callbacks)
- JavaScript: What if jQuery animation doesn't fire/start? JavaScript: Ko darīt, ja jQuery animācijas nav uguns / sākt?
- JavaScript: GIFless animation. JavaScript: GIFless animāciju. Animate images,logos with jQuery Dzīva attēlus, logotipus ar jQuery












































