Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.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
基于目标URL中的#执行javascript_Javascript_Jquery_Url_Checkout_Fragment Identifier - Fatal编程技术网

基于目标URL中的#执行javascript

基于目标URL中的#执行javascript,javascript,jquery,url,checkout,fragment-identifier,Javascript,Jquery,Url,Checkout,Fragment Identifier,当有人单击指向#签出ID的元素时,我想执行一个脚本 这是一个要素: <a class="lp-element lp-pom-button" id="lp-pom-button-293" href="**#checkoutID**" target="_self" data-params="true"><span class="label">Checkout

当有人单击指向#签出ID的元素时,我想执行一个脚本

这是一个要素:

<a class="lp-element lp-pom-button" id="lp-pom-button-293" href="**#checkoutID**" target="_self" data-params="true"><span class="label">Checkout</span></a>

我正在努力在#之后检索字符串,查看它是否包含“checkout”,然后使用checkoutID作为price的值来执行脚本,在本例中,price值只是项目的一个ID。请大家在这里提供一些建议。如果您想查看您可以使用的当前url,谢谢

window.location.href;
并且,如果要在某个事件上调用函数,请使用:

document.querySelector(‘#bttonOrElementID’).addEventListener(‘click’, function(){
//your function goes here
});

window.location.hash
将更加简洁,如副本的答案所述。
document.querySelector(‘#bttonOrElementID’).addEventListener(‘click’, function(){
//your function goes here
});