我需要用URL中的哈希替换斜杠。其他一切保持不变。
例如
:
www.example.com/main/events/event-1
Run Code Online (Sandbox Code Playgroud)
需要更改为:
www.example.com/main/events#event-1
Run Code Online (Sandbox Code Playgroud)
(jQuery解决方案是最佳选择,插件可以)
根据OP的评论进行更新:
使用此代码:
function outputStatus(e)
{
if (e.success && $.url.segment(1) == 'events')
{
// IF Flash SWF loads success AND on events page
var url = $.url.attr('source'); // gets current URL
var new_url = url.replace(/\/([^\/]+)$/, "#$1"); // replaces last slash with a hash
window.location = new_url; // sets the current URL to the new URL
}
}
Run Code Online (Sandbox Code Playgroud)
该URL被更改了两次(因此www.example.com/main/events/event-1
变为www.example.com/main/events#event-1
,然后变为www.example.com/main#events#event-1
)。