給你的鏈接,並提醒每一個id
這樣你就可以用JavaScript瞄準它,默認情況下也隱藏你的警覺,這樣的事情:
<a id="testenv" href="www.footester.com/foofootestest">Test Environment #1</a>
<div id="testalert" style="display:none" class="alert alert-info">
<!-- ... -->
</div>
然後使用JavaScript當鏈路是火mouseover
事件徘徊是這樣的:
var testenv = document.getElementById("testenv"),
testalert = document.getElementById("testalert");
testenv.addEventListener("mouseover", function(event) {
testalert.style.display = "block";
}, false);
只是爲了好玩,你還可以添加一個mouseout
事件做出警報再次消失,當鼠標下車的鏈接(不徘徊了):
testenv.addEventListener("mouseout", function(event) {
testalert.style.display = "none";
}, false);
下面的代碼片段塊中的全部代碼:
var testenv = document.getElementById("testenv"),
testalert = document.getElementById("testalert");
testenv.addEventListener("mouseover", function(event) {
testalert.style.display = "block";
}, false);
testenv.addEventListener("mouseout", function(event) {
testalert.style.display = "none";
}, false);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<a id="testenv" href="www.footester.com/foofootestest">Test Environment #1</a>
<div class="container">
<div id="testalert" style="display:none" class="alert alert-info">
<strong>Note: The testers are not using this link as a part of their test environment!</strong>
</div>
</div>
在這裏,您可以與bootply代碼(引導測試沙箱)玩:http://www.bootply.com/TfrhmIbqq8
看看[JavaScript的'addEventListener'功能與'mouseover'(https://developer.mozilla.org/en-US/docs/Web/Events/ mouseover)事件,或者如果你使用jQuery庫(基本上是一個JavaScript框架),你可以利用它的['hover'](https://api.jquery.com/hover/)函數。 – webeno
你可以使用'a〜div' css規則:https://jsfiddle.net/khrismuc/ww6wqv7q/ –
你可能想要接受其中一個答案作爲正確的答案... – webeno