我在这里的第一个帖子,但我已经学到了很多,潜伏=)这一次,我找不到一个问题的解决方案,尽管它看起来很容易实现。
我有一个用Feed2JS生成的博客帖子链接列表。不幸的是,RSS提要为我不想要的链接添加了锚点。我不能更改提要,因为它是在RapidWeaver中自动生成的。
有没有可能用jQuery从url的散列中删除所有内容?例如:更改
http://www.example.com/blog/files/398e042ea42b7ee9d1678b3c53132fc3-31.php#unique-entry-id-31
至
http://www.example.com/blog/files/398e042ea42b7ee9d1678b3c53132fc3-31.php
我是jQuery的新手,还有很多东西需要学习,所以请简单回答。
耶罗恩
发布于 2012-01-12 18:01:16
如果你只想截断url,你可以这样做。
var url = "http://www.example.com/blog/files/398e042ea42b7ee9d1678b3c53132fc3-31.php#unique-entry-id-31";
var index = url.indexOf('#') != -1 ? url.indexOf('#') : url.length
alert(url.substring(0,index));输出:
http://www.example.com/blog/files/398e042ea42b7ee9d1678b3c53132fc3-31.php示例:http://jsfiddle.net/2dXXx/
发布于 2012-01-12 17:58:32
你不需要jQuery来做这件事,因为javascript通过window.location支持它。
看看这个答案,看看你想要做什么,javascript window location href without hash?。
发布于 2012-01-12 17:58:44
我喜欢这样做:
var a = document.createElement("a");
a.href = "http://www.example.com/blog/files/398e042ea42b7ee9d1678b3c53132fc3-31.php#unique-entry-id-31";
alert(a.protocol + "://" + a.host + a.pathname + a.search);http://jsfiddle.net/karim79/7pMbk/1
https://stackoverflow.com/questions/8833054
复制相似问题