[英]How come the CSS in my JavaScript won't work?
當我單擊它時,我試圖使一個框彈出。 這是盒子的HTML:
<div id="content_1">
<p>Hello</p>
<p>Please push the button</p>
<p><input type="button" id="go_button" value="Go"/> </p>
</div>
<div id="box">
<p>hello</p>
</div>
這是JavaScript和CSS:
$(document).ready(function() {
$("#content_2").on("click",function(){
.css("z-index",3);
}
}
這是樣式,以防萬一:
#go_button {
}
#content_1 {
margin:20px auto;
position:fixed;
width:1000px;
text-align:center;
border:1px solid #d0d0d0;
box-shadow:1px 1px 5px #aaa;
border-radius:15px;
background:#99FF99;
z-index:3;
}
#box {
position:fixed;
top:100px;
left:300px;
z-index:1;
width:600px;
height:300px;
background:green;
}
body {
background:#f7f7f7;
}
您不能在沒有任何啟動的情況下調用方法鏈。 我們在您的標記中看不到ID為content_2
的元素。 也許您是想將其應用於#content_1
。
$(document).ready(function() {
$("#content_2").on("click",function(){
// Apply to this
$(this).css("z-index",3);
});
});
如果CSS要應用於其他元素而不是content_2
( this
),請使用其選擇器。
$(document).ready(function() {
$("#content_2").on("click",function(){
$('#box').css("z-index",3);
});
});
請注意,除非您指定了position: absolute
或position: fixed
,否則z-index
不會起作用。
嘗試這個
$(document).ready(function() {
$("#content_2").on("click",function(){
$(this).css("z-index",3);
}
}
看來您沒有將CSS應用於任何事物:
$(document).ready(function() {
$("#content_2").on("click",function(){
$('#box').css("z-index",3);
}
}
另外,未定義#content_2
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.