- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个“站点”,在这个站点中我有三个按钮,可以在 3 ...窗口(?)之间切换。这是通过隐藏 2 个同时保持 1 个可见的函数完成的。三个“窗口”是div。隐藏并使 div 可见的函数针对“id="wrapper"”的子项,它不应该针对 Wrappers 的孙子项,因此问题不应该在那里,但函数是唯一可能干扰的东西,据我所知。
三个 div 之一,里面有 div 没问题,但其他 div 不能包含 div,我不得不使用 <p>
用于包含内容,但当我想将图像用作按钮等时,它就不起作用了。
我在过去一天检查了 html 几次,但我找不到任何问题,我会继续自己尝试,但我可能会在 1-3 天内失去互联网,我不想被“搁浅”。
我的三个“包装器”子级是“WindowTwo”、“WindowThree”和“container”类。如果将 div 放在 WindowTwo 和 WindowThree 中,您会注意到第一个按钮窗口变为空白。容器是可以毫无问题地在 div 中包含 div 的容器
http://codepen.io/anon/pen/WbjzWL
我知道我的代码很乱,而且我的喋喋不休更乱,对此深表歉意,并在此先感谢您的任何输入:)
function toggleDiv(target) {
var div = document.getElementById('wrapper').getElementsByTagName("div");
if (target == 1) {
div[0].style.display = 'block';
div[1].style.display = 'none';
div[2].style.display = 'none';
} else if (target == 2) {
div[0].style.display = 'none';
div[1].style.display = 'block';
div[2].style.display = 'none';
} else {
div[0].style.display = 'none';
div[1].style.display = 'none';
div[2].style.display = 'block';
}
};
.ButtonOveral {
position: absolute;
background-color: yellow;
width: 90px;
height: 45px;
left: 4px;
top: -15px;
}
.ButtonOveral2 {
position: absolute;
background-color: red;
width: 90px;
height: 45px;
left: 4px;
top: 40px;
}
.ButtonOveral3 {
position: absolute;
background-color: yellow;
width: 90px;
height: 45px;
left: 4px;
top: 100px;
}
.ButtonOveral4 {
position: absolute;
background-color: blue;
width: 90px;
height: 45px;
left: 4px;
top: 160px;
}
.ButtonOveral5 {
position: absolute;
background-color: purple;
width: 90px;
height: 45px;
left: 4px;
top: 220px;
}
.ButtonOveral6 {
position: absolute;
background-color: red;
width: 90px;
height: 45px;
left: 4px;
top: 280px;
}
.Red {
position: absolute;
background-color: red;
width: 90px;
height: 85px;
left: 4px;
top: 350px;
}
/*
pointer-events: none; // enables you to click through transparent divs
*/
img {
pointer-events: none;
position: absolute;
z-index: 100;
left: 34px;
top: 562px;
margin-top: -33px;
margin-left: -33px;
}
.moneyHolder {
position: relative;
height: 50px;
width: 810px;
background-color: red;
left: 83px;
top: -8px;
}
#newpost {
display: none;
position: relative;
left: 83px;
top: -8px;
width: 810px;
height: 550px;
background-color: green;
}
#SecondWindow {
position: relative;
left: 83px;
top: -8px;
width: 810px;
height: 550px;
background-color: hsla(359, 35%, 39%, 0.35);
}
#ThirdWindow {
display: none;
position: relative;
left: 83px;
top: -8px;
width: 810px;
height: 550px;
background-color: blue;
}
.upgradeHolder {
position: absolute;
border: 1px solid blue;
top: 0px;
left: 0px;
width: 90;
height: 598;
background-color: black;
}
.Lemon {
width: 90px;
height: 55px;
background-color: #B93437;
margin: 0px 0px 5px 0px;
}
.Lemon2 {
width: 90px;
height: 55px;
background-color: purple;
margin: 5px 0px 5px 0px;
}
.savebutton {
width: 90px;
height: 55px;
background-color: pink;
margin: 5px 0px 5px 0px;
}
#button,
#button2,
#button3 {
display: inline-block;
background: hsla(39, 100%, 50%, 0.59);
width: 90px;
height: 30px;
margin: 0 0 20px;
}
<div class="moneyHolder">
<h1 style="cursor:default"> Money: <span id="money">0</span></h1>
</div>
<div id="wrapper">
<div class="WindowTwo" id="SecondWindow">
<p class="ButtonOveral" onclick="ProtoType()" id="tooltip22">Price: <span id="RedId1">0</span>
</br>Bank: <span id="Reds1">0</span>
</p>
</div>
<div class="WindowThree" id="ThirdWindow"></div>
<div class="container" id="newpost" onclick="GatherMoney()">
<div class="Lemon" onclick="Build(0);">Lemon: <span id="Building1Cost">0</span>
</br>PerSec: <span id="Building1PerSec">1</span>
</br>Quantity: <span id="Building1Qty">0</span>
</div>
<div class="saveButton" style="cursor:default" onclick="save()">
<h2>Save </h2>
</div>
</div>
<!-- Below is "window" changer
-->
</div>
<div class="upgradeHolder">
<div id="button" onclick="toggleDiv(0)">one</div>
<div id="button2" onclick="toggleDiv(1)">two</div>
<div id="button3" onclick="toggleDiv(2)">Three</div>
</div>
最佳答案
不要为此使用 getElementsByTagName
。它将选择作为 wrapper
后代的所有 div
。使用 children
代替。 wrapper
中的所有元素都是“窗口”divs。因此,如果您使用它,它将按您的预期工作。
function toggleDiv(target){
var div = document.getElementById('wrapper').children;
if (target == 1) {
div[0].style.display = 'block';
div[1].style.display = 'none';
div[2].style.display = 'none';
} else if(target == 2) {
div[0].style.display = 'none';
div[1].style.display = 'block';
div[2].style.display = 'none';
}else{
div[0].style.display = 'none';
div[1].style.display = 'none';
div[2].style.display = 'block';
}
};
或者更好的解决方案:
var div = document.querySelectorAll("#wrapper > div");
这仅选择 wrapper
或 div
类型的直接后代(子代)。
关于javascript - div 里面的 div,搞砸了,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28055790/
在我的应用程序中,我使用 scrape(string url) 方法从网页中抓取链接。可以说它每次都返回我 10 个 url。 我想从每个抓取的 url 中抓取 10 个链接。 长话短说: (第 1
正如标题所说,我需要将 php 放入由 php 回显的 javascript 中 例如: if (something) then (some php)') ?> 这不是真正的代码,只是可能有助于理解
我有一个 ng-repeat 使用 ng-switch 来分隔 ng-repeat 内部的部分,我想在 ng-switch 组上应用一个 orderby 过滤器,但我似乎无法让它工作:
我是 shell 的新手。我不太了解以下功能。这个函数基本上把小时加1。 我想知道为什么开发人员在 $g_current_hour+1 前面放了“10#”。根据我的理解,shell 中的剂量 # 是指
为了在 MongoDB 中对元素进行分组和计数,我已经筋疲力尽了。有很多帖子,但没有一个是我需要的。 这是一个基于以下内容的示例: styvane answer db.VIEW_HISTORICO.a
int main() { int count = 0; string prev = " "; string current; while (cin>>current)
$0表示传递给swift闭包的第一个参数,是swift语言的语法糖。swift会自动为内联闭包提供速记参数名称,可使用$0,$1,$2等名称来引用闭包参数的值。 代码
我想把这个 If 放在宏中,但它总是给我一个错误。我不知道“或”用得是否正确。 Dim SMAT As String SMAT = "blahblahblah" (...) If Ce
这是 JSFiddle 链接:https://jsfiddle.net/fmdsu9Lo/ 我想添加一个悬停功能,以便将鼠标悬停在菜单上将在该菜单选项卡上应用 .current 样式,同时将其从当前打
是否可以在 SQL 中执行类似的操作? SELECT SUM(jobRequirements.number) as total, SUM(jobRequirements.number WHER
我有 3 个 SQL 表。 游戏 wo_tenis_partidos 选择 wo_tenis_pronosticos 配额 wo_tenis_cuotas_ha2 我需要获取满足两个条件的所有行: 条
我有这张乘客表日期: 这意味着在 Reservation 000004 中,有两个行程,分别是 Itinerary 0000010 (AAC Hangar - Anvaya Cove) 和 00000
里面
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 已关闭 9 年前。 此问题是由拼写错误或无法再重现的问题引起的。虽然类似的问题可能是 on-topic在这里
我在模态框内显示一个弹出窗口,我可以在关闭时隐藏它,但在点击模态框外时无法隐藏它。我试着在关闭时隐藏它,这很好。代码在这里 $('.close, .close-button').click(funct
我所在的团队正在使用 MVC 架构开发 C# 程序。 当我完成 MVC 教程时,我有一些疑问。请帮我澄清一下这个疑惑。 1) Controller 可以对 View 进行哪些修改? 2)我认为所有 U
我正坐在一些通过#defines 生成大量代码的遗留代码上。现在我知道在 #define 中不可能有 #ifdef,但是 #if 可能吗?我想为特定类型添加一些特化。 (无需进行重大更改,例如使用模板
这是我试图用来创建触发器的代码: -- Dumping structure for trigger kavanga_lead.click_links_insert DROP TRIGGER IF EX
我想写这样的东西: #define COV_ON(x) \ #ifdef COVERAGE_TOOL \ _Pragma (CO
我在这样的定义的帮助下初始化一个结构数组: #define FLAGCODE(name) { #name, MNT_ ## name } struct { const char
我尝试将 css 和 jquery 应用于 div 元素,但它不接受 $(this) 参数。我想知道为什么我不能使用 $(this) 作为 div 元素的引用。 blabla.css({ 'top':
我是一名优秀的程序员,十分优秀!