JavaScript: Get anchor from URL JavaScript: Get ทอดสมอจาก URL
Posted on 10. โพสต์ใน 10. Jun, 2009 by Dragos in Apps , Coding , JavaScript & Ajax , PHP มิ.ย., 2,009 โดย 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-1'; / / หากคุณต้องการใช้ url ในปัจจุบันการใช้หน้าต่าง: var window.location = url; var anchor=url.hash; //anchor with the # character ทอดสมอ var = url.hash; / Anchor / กับตัว # var anchor2=url.hash.substring(1); //anchor without the # character var anchor2 url.hash.substring = (1) / Anchor / โดยตัวอักษร #
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: ถ้าคุณ iterating ผ่านลิงค์ในหน้า with JQuery และ $ (นี้) ได้กำหนดลิงค์เดียวแล้วพบทอดสมอของวัตถุนี้คุณจะต้องใช้รหัสต่อไปนี้:
var anchor=$(this).attr("hash"); ทอดสมอ var = $ (นี้) attr. (กัญชา ""); Related posts: บทความที่เกี่ยวข้อง:
- Javascript: How to validate email address with JavaScript? Javascript: การตรวจสอบที่อยู่อีเมลด้วย JavaScript?
- JavaScript: How to get the index (position within a group) of an object with jQuery? JavaScript: วิธีการรับดัชนี (ตำแหน่งภายในกลุ่ม) ของวัตถุด้วย jQuery?
- JavaScript: Send function as a parameter to another function (callbacks) JavaScript: ส่งหน้าที่เป็นพารามิเตอร์ทำงาน (callbacks อื่น)
- JavaScript: What if jQuery animation doesn't fire/start? JavaScript: ถ้าเคลื่อนไหว jQuery จะไฟไม่ / เริ่ม?
- JavaScript: GIFless animation. JavaScript: ภาพเคลื่อนไหว GIFless. Animate images,logos with jQuery ภาพชีวิตโลโก้กับ jQuery












































