JavaScript: Get anchor from URL JavaScript: Hanki ankkuri URL-osoitteesta
Posted on 10. Postitettu 10. Jun, 2009 by Dragos in Apps , Coding , JavaScript & Ajax , PHP Kesäkuu, 2009 Dragos ja sovellukset, Coding, JavaScript-ja Ajax, PHP
To get the anchor from an URL (this is the text after the # character) in JavaScript you can use the following code: Saada ankkuri alkaen URL (tämä on tekstin jälkeen #-merkki) JavaScript voit käyttää seuraavaa koodia:
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" / / jos haluat ottaa nykyistä URL-ikkunan käyttö: var url = window.location; var anchor=url.hash; //anchor with the # character var ankkuri = url.hash, / ankkuri on #-merkki var anchor2=url.hash.substring(1); //anchor without the # character var anchor2 = url.hash.substring (1), / / ankkuri ilman #-merkki
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: Jos olet iteroimalla läpi linkit sivun kanssa jQuery, ja $ (tämä) määritellään yksi linkki, sieltä löytää ankkuri tämän kohteen sinun tulee käyttää seuraavaa koodia:
var anchor=$(this).attr("hash"); var ankkuri = $ (tämä). attr ( "hash"); Related posts: Liittyvien virkojen:
- JavaScript: How to get the index (position within a group) of an object with jQuery? JavaScript: Miten saada indeksi (asema ryhmä) objektin kanssa jQuery?
- Javascript: How to validate email address with JavaScript? Javascript: Miten vahvistaa sähköpostiosoitteesi JavaScript?
- JavaScript: Send function as a parameter to another function (callbacks) JavaScript: Lähetä toimivat parametri toisen toiminnon (kutsuja)
- JavaScript: What if jQuery animation doesn't fire/start? JavaScript: Mitä jos jQuery animaatio ei palo / alku?
- JavaScript: Where do I Find All Properties for All HTML Elements ? JavaScript: Mistä löydän kaikki ominaisuudet kaikki HTML-elementit?












































