如何从文档 URL 获取哈希
How to get hash from document url
如果我使用:
jQuery(document).ready(function() {
console.log($(this));
});
然后在控制台中我有对象:
[Document mypage.html#weather]
我怎样才能获得最后一个 ID?在此示例中,这是 #weather。我想在选择器中使用警报 #weather,例如$(data_from_console + '.add').val();
是否要获取最后一个具有 ID 属性的元素?
㞖:
$(document).ready(function () {
console.log($('body *[id]').eq(-1));
});
编辑仔细观察,您是否正在寻找哈希标签?韦普如果您的 URL mypage.html#weather
您想要 #weather?
在这种情况下,请尝试:
$(document).ready(function () {
console.log(document.location.hash);
});
你可以使用 last() 方法。试试这个:
$(document).ready(function() {
$('body *').each(function() { //selects all elements in body which got id
var lastEle = $(this).last(); //selects last one of them
console.log(lastEle.attr('id'));//returns it's id to console log
});
});
相关文章:
- AngularJS:获取链接中没有哈希的查询字符串值
- 如何从文档 URL 获取哈希
- 如何使用JavaScript获取包含哈希片段的先前url
- 获取javascript中的DOM元素哈希
- 从 URL 中获取 DIV 哈希
- JavaScript 获取以前的哈希值
- 获取哈希并存储在变量中
- 使用哈希来获取网址,而无需重定向到新页面
- Javascript - 获取带有哈希的 url 参数
- Javascript - 如何使用哈希获取文档引用
- 如何在 Javascript 中获取 url 的哈希部分(新的浏览器版本)
- 如何从哈希 url 获取参数
- 使用对象哈希映射上的索引获取值
- 使用Javascript从url中获取空哈希值
- 如何从 URL 获取哈希参数
- 获取哈希值而不将其分配给变量
- 从请求url获取哈希参数
- 在nodejs中通过url获取哈希值
- 正在从url中获取哈希链接
- 在同一页面regex中获取哈希链接