Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/382.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 当内联链接“0”时,如何运行jQuery命令#&引用;单击或输入url,就像链接到reddit评论时一样_Javascript_Jquery - Fatal编程技术网

Javascript 当内联链接“0”时,如何运行jQuery命令#&引用;单击或输入url,就像链接到reddit评论时一样

Javascript 当内联链接“0”时,如何运行jQuery命令#&引用;单击或输入url,就像链接到reddit评论时一样,javascript,jquery,Javascript,Jquery,我希望在单击内联链接或将其输入URL时运行脚本,如。与reddit链接到评论时发生的情况类似 我该怎么做呢?我会给你一个主意。假设你想处理所有的标签 html <a href="http://site.com/index.php#comment">Link<a> $('a').click(function(event){ event.preventDefault(); var url = $(this).attr('href'); var lastPart = url.

我希望在单击内联链接或将其输入URL时运行脚本,如。与reddit链接到评论时发生的情况类似


我该怎么做呢?

我会给你一个主意。假设你想处理所有的标签

html

<a href="http://site.com/index.php#comment">Link<a>
$('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
}
});