我不能得到這個jQuery函數與傳遞的div id作爲一個參數,而不是實際輸入的腳本里面的DIV ID(如果我沒有這樣的說法,然後我需要一個工作每個div的腳本)。任何想法爲什麼這不起作用?我對jQuery比較陌生。調試器說「的ReferenceError:找不到變量:家」jQuery的傳遞參數失敗 - 的作品,而不傳遞參數
懸停在藍色的div應適用另一CSS樣式類和轉DIV紅色。
感謝任何幫助,謝謝。
function hoverOverWindows(div) {
var id = "#" + div;
$('id').addClass('hover-over-windows-style');
};
function hoverAwayFromWindows(div) {
var id = "#" + div;
$('#div').removeClass('hover-over-windows-style');
};
.home-match-type {
width: 47%;
height: 300px;
margin-top: 50px;
float: left;
position: relative;
overflow: hidden;
}
.home-match-type-left { margin-right: 3% }
.img-text-container {
width: auto;
height: auto;
bottom: 0;
position: absolute;
padding: 15px;
background: rgba(60, 122, 173, 0.95);
}
.img-text-container-type-2 { background: rgba(60, 122, 173, 0.95) }
.img-text {
text-align: left;
margin: 0;
display: inline-block;
}
h3.img-text.img-header { float: left }
h3.img-text.img-header.be-central { float: none }
.img-header {
padding-bottom: 5px;
text-transform: uppercase;
border-bottom: 1px solid rgba(213, 213, 213, 0.3);
}
.hover-over-windows-style {
background: red;
height: 100%;
}
<link href="assets/css/lib/bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<article class="home-match-type home-match-type-left">
<div class="img-text-container img-text-container-type-2" id="home-m-t-1" onmouseover="hoverOverWindows(home-m-t-1)" onmouseout="hoverAwayFromWindows(home-m-t-1)">
<h3 class="img-text img-header be-central windows-type-2"><a href="matches/blitz.html">Some Text</a></h3>
<p class="img-text text-align-centre windows-type-2">lorem ipsum sid etc whaetveer lorem ipsum sid etc whaetveer lorem ipsum sid etc whaetveer lorem ipsum sid etc whaetveer lorem ipsum sid etc whaetveer lorem ipsum sid etc whaetveer lorem ipsum sid etc whaetveer </p>
</div>
</article>
你的頭腦,包括你的JavaScript的一部分,你使用的是可變的 '家'?我想看看你分配給'家'以及那個變量正在做什麼。 –
$('id')'應該是'$(id)'。引號阻止擴展變量。 – Barmar
不應該在引號內的div ID? – simlev