JavaScript: Get anchor from URL JavaScript: Πάρτε άγκυρα από URL
Posted on 10. Καταχωρήθηκε στις 10. Jun, 2009 by Dragos in Apps , Coding , JavaScript & Ajax , PHP Ιούνιος, 2009 από Dragos σε Apps, Κωδικοποίηση, 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 # comment = '-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 ( "hash")? 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: Αποστολή λειτουργεί ως παράμετρος σε μια άλλη λειτουργία (callbacks)
- JavaScript: What if jQuery animation doesn't fire/start? JavaScript: Τι γίνεται αν jQuery κινούμενα σχέδια δεν φωτιά / εκκίνηση;
- JavaScript: Where do I Find All Properties for All HTML Elements ? JavaScript: Πού μπορώ να βρω τα ακίνητα για όλα τα στοιχεία HTML;












































