如何在HTML中突出显示当前的id元素
How to highlight current id element in HTML
我想突出显示当前'#id'片段:
如果URL是:http://localhost:4321/store/zapakshop/#943
then id=943应该突出显示…
我已经试过了,但它不工作:
$(document).ready(function () {
$(window.location.hash).effect("highlight", {
color: "#FF0000"
}, 3000);
});
帮我…
Snook用CSS3做了一个很好的例子。下面是一个工作示例,改编自该页:是的,它正在工作,但它正在永久地改变颜色,我只是想要一个闪光灯…——user2217267
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<style type="text/css" media="all">
:target {
-webkit-animation: target-fade 3s 1;
-moz-animation: target-fade 3s 1;
}
@-webkit-keyframes target-fade {
0% { background-color: rgba(0,0,0,.1); }
100% { background-color: rgba(0,0,0,0); }
}
@-moz-keyframes target-fade {
0% { background-color: rgba(0,0,0,.1); }
100% { background-color: rgba(0,0,0,0); }
}
</style>
</head>
<body>
<p>Click the link to <a href="#goal">target the div</a>.
<div id="goal">This is the div. This is the div. This is the div. This is the div. This is the div. This is the div. This is the div. This is the div. This is the div. This is the div. This is the div. This is the div. This is the div. This is the div. This is the div. This is the div. This is the div. This is the div. This is the div. This is the div. This is the div. This is the div. This is the div. This is the div. </div>
</body>
</html>
你必须在包含jquery之后再包含jquery UI:
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.2/jquery-ui.min.js"></script>
您可以在CSS中使用目标伪类。这将突出显示当前在URL上以散列形式存在的具有ID的元素。
*:target {
background-color: yellow;
}
MDN: https://developer.mozilla.org/en-US/docs/css/%3Atarget
如果你只是将样式应用于与URL中哈希值相同ID的元素,你可以通过target
伪选择器:
:target {
color:#f00;
}
来源:http://css-tricks.com/almanac/selectors/t/target/
Sacha抢先了我一步,但我将把链接留给CSS技巧文章,该文章很好地解释了这个伪选择器。
我使用
document.getElementById(id).style.outline = 'red solid 3px';
适用于所有有大纲的元素(比如textarea)。如果你想让它闪烁100毫秒,你的下一行可以是:
window.setTimeout(unoutline, 100);
,你将定义一个函数unoutline,像这样:
function unoutline()
{
document.getElementById(id).style.outline = '';
}
您可以在http://www.staerk.de/regex上看到实际的代码。
相关文章:
- Javascript:表单验证getElementById仅返回第一个id元素
- 如何为每个带有数字的id元素使用Javascript函数
- 使用regex选择ID元素
- Bootstrap Navbar在选择ID元素后未折叠
- JavaScript-更改一组包含特定文本和变量ID元素的链接
- 父页面中的 JQuery 未在部分视图中检测到 id 元素
- ID 元素在作为参数给出时返回
- 当 Javascript 中的 POST ID 元素插入 PDO 时,数据库中没有结果
- 为什么变量值不显示在 id 元素中
- 如何查找 id 元素的文本值
- 使用 ajax 将 id 元素传递给数据库
- 从另一个HTML文件中获取ID元素
- 正在克隆html标记id元素
- 如何在html中循环使用ID元素
- 获取动态生成的id元素的内部文本发送到谷歌分析
- 如何通过tagname检查ID元素
- jQuery滚动到底部的ID元素
- 检查Id元素javascript
- 在我显示一个id元素后,页面跳转到顶部
- 如何在HTML中突出显示当前的id元素