-2

我想在单击内联链接时运行脚本,或者输入像http://site.com/index.php#comment这样的 URL 。类似于链接到评论时在 reddit 上发生的情况。

我怎样才能做到这一点?

4

1 回答 1

-1

我会给你想法..假设你想处理所有的标签

html

<a href="http://site.com/index.php#comment">Link<a>

javascript

$('a').click(function(event){
event.preventDefault();
var url = $(this).attr('href');
var lastPart = url.split('#')[1];
if(lastPart=== 'comment') {
//do something
} else if(lastPart === 'post') {
//do something
}
});
于 2013-08-29T04:51:21.590 回答