URI 和 jQuery 帮助

发布于 2024-08-17 05:51:14 字数 119 浏览 1 评论 0原文

是否可以使用javascript获取URI,或者是否可以分解链接的href,如果可以的话,我正在尝试运行一些具有悬停和单击事件的ajax,并且每个ajax的方法调用是相同的,所以我需要能够获取在 URI 中传递的唯一 ID。

Is it possible o get the URI with javascript or is possible to break apart the href of the link and if so how, I am trying to run some ajax that has hover and click events and the method call for each ajax is the same so I need to be able get the unique ID that is passed in the URI.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

瞎闹 2024-08-24 05:51:14

锚点提供与 window.location 中相同的属性。

例如

<a id="mylink" href="http://website.com/page.html#content">Link</a>

var anchor = $('a#mylink')[0]; // [0] to access DOM node

anchor.href; // => http://website.com/page.html#content
anchor.pathname; // => page.html
anchor.hash; // => #content
anchor.protocol; // => http:

An anchor makes available the same properties that you find in window.location.

E.g.

<a id="mylink" href="http://website.com/page.html#content">Link</a>

jQuery:

var anchor = $('a#mylink')[0]; // [0] to access DOM node

anchor.href; // => http://website.com/page.html#content
anchor.pathname; // => page.html
anchor.hash; // => #content
anchor.protocol; // => http:
未央 2024-08-24 05:51:14

HTML

<a href="/users/1/details">User</a>

jQuery

$("a").click(function(e){
   var href = $(this).attr('href'); // = /users/1/details

   //Once you have it, get the id:
   var id = href.split('/')[2]; // returns 1

   //Do something with it

   e.preventDefault(); // Keep the original link from being followed
}); 

HTML

<a href="/users/1/details">User</a>

jQuery

$("a").click(function(e){
   var href = $(this).attr('href'); // = /users/1/details

   //Once you have it, get the id:
   var id = href.split('/')[2]; // returns 1

   //Do something with it

   e.preventDefault(); // Keep the original link from being followed
}); 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文