JavaScript: Get anchor from URL JavaScript: Dapatkan jangkar dari URL
Posted on 10. Dikirim di 10. Jun, 2009 by Dragos in Apps , Coding , JavaScript & Ajax , PHP Jun, 2009 oleh Dragos dalam Apps, Coding, 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: Untuk mendapatkan jangkar dari sebuah URL (ini adalah teks setelah # karakter) dalam JavaScript Anda dapat menggunakan kode berikut:
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'; / / jika Anda perlu untuk mengikuti arus url jendela menggunakan: var url = window.location; var anchor=url.hash; //anchor with the # character var jangkar = url.hash; / / anchor dengan karakter # var anchor2=url.hash.substring(1); //anchor without the # character var anchor2 = url.hash.substring (1); / / anchor tanpa karakter #
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: Jika Anda iterasi melalui link pada halaman dengan JQuery, dan $ (ini) mendefinisikan sebuah link, kemudian untuk menemukan jangkar objek ini Anda akan perlu menggunakan kode berikut:
var anchor=$(this).attr("hash"); var anchor = $ (ini). attr ( "hash"); Related posts: Related posts:
- Javascript: How to validate email address with JavaScript? Javascript: Bagaimana untuk memvalidasi alamat email dengan JavaScript?
- JavaScript: How to get the index (position within a group) of an object with jQuery? JavaScript: Cara mendapatkan indeks (posisi dalam grup) dari sebuah objek dengan jQuery?
- JavaScript: Send function as a parameter to another function (callbacks) JavaScript: Kirim fungsi sebagai parameter ke fungsi lain (callback)
- JavaScript: What if jQuery animation doesn't fire/start? JavaScript: Bagaimana jika tidak animasi jQuery api / start?
- JavaScript: GIFless animation. JavaScript: GIFless animasi. Animate images,logos with jQuery Bernyawa gambar, logo dengan jQuery












































