- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我的目标是一次只打开一个开关。为此,我想检查切换是否为:可见。,并创建一个条件语句来隐藏其他当前打开的 ID。但是,当我运行我的代码时,无论是否打开,它都会返回 false。我错过了什么?
请只看 js 开头引用 .bases 的代码,因为我没有为其他实例创建它,因为我无法让它工作。
if ($(".bases, .protein, .toppings, .sauces, .extratoppings, .teas, .desserts").is(":visible")) {
$(".bases, .protein, .toppings, .sauces, .extratoppings, .teas, .desserts").hide();
}
$("#bases").click(function() {
$(".bases").slideToggle("slow", );
if ($('.bases').is(':visible')) {
console.log("visible");
} else {
console.log("not visible");
}
});
$("#protein").click(function() {
$(".protein").slideToggle("slow");
});
$("#toppings").click(function() {
$(".toppings").slideToggle("slow");
});
$("#sauces").click(function() {
$(".sauces").slideToggle("slow");
});
$("#extratoppings").click(function() {
$(".extratoppings").slideToggle("slow");
});
$("#teas").click(function() {
$(".teas").slideToggle("slow");
});
$("#desserts").click(function() {
$(".desserts").slideToggle("slow");
});
html {
height: 100%;
}
body {
display: flex;
flex-direction: column;
height: 100vh;
/* Avoid the IE 10-11 `min-height` bug. */
}
.content {
flex: 1 0 auto;
/* Prevent Chrome, Opera, and Safari from letting these items shrink to smaller than their content's default minimum size. */
padding: 20px;
}
.footer {
flex-shrink: 0;
/* Prevent Chrome, Opera, and Safari from letting these items shrink to smaller than their content's default minimum size. */
padding: 20px;
}
a {
text-decoration: none;
color: white;
}
* {
box-sizing: border-box;
}
body {
margin: 0;
font: 16px Sans-Serif;
}
h1 {
margin: 0 0 20px 0;
}
p {
margin: 0 0 20px 0;
}
footer {
background: #42A5F5;
color: red;
}
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td,
th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
ul,
li {
text-decoration: none;
list-style: none;
margin: 3%;
margin-bottom: 5%;
width: auto;
}
#menuitems {
display: flex;
width: auto;
margin: 0%;
margin-bottom: 5%;
align-items: center;
justify-content: center;
background: blue;
color: white;
text-decoration: none .caloriecalculatormain {
display: none !important;
}
<!DOCTYPE html>
<html>
<head>
<title>Padthai calc</title>
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body>
<div class="content">
<h1>PADTHAI CALORIE CALCULATOR</h1>
</div>
<ul id="menuitems">
<li><button id="bases">Main Dish</button></li>
<li><button id="protein">Soup</button></li>
<li id="teas"><button>Teas</button></li>
<li id="desserts"><button>Desserts</button></li>
</ul>
<div>
<div class="bases">
<h1>Main Dish</h1>
<table>
<tr>
<th>Company</th>
<th>Contact</th>
<th>Country</th>
</tr>
<tr>
<td>Alfreds Futterkiste</td>
<td>Maria Anders</td>
<td>Germany</td>
</tr>
<tr>
<td>Centro comercial Moctezuma</td>
<td>Francisco Chang</td>
<td>Mexico</td>
</tr>
<tr>
<td>Ernst Handel</td>
<td>Roland Mendel</td>
<td>Austria</td>
</tr>
<tr>
<td>Island Trading</td>
<td>Helen Bennett</td>
<td>UK</td>
</tr>
<tr>
<td>Laughing Bacchus Winecellars</td>
<td>Yoshi Tannamuri</td>
<td>Canada</td>
</tr>
<tr>
<td>Magazzini Alimentari Riuniti</td>
<td>133</td>
<td>152</td>
</tr>
</table>
</div>
<div class="protein">protein</div>
<div class="toppings">toppings</div>
<div class="sauces">sauces</div>
<div class="extratoppings">extratoppings</div>
<div class="teas">teas</div>
<div class="desserts">Desserts</div>
</div>
</body>
</html>
<style>
</style>
<footer class="footer">
<div id="total">Total</div>
<div id="carbs">Carbs</div>
</footer>
</body>
</html>
最佳答案
无论您是打开还是关闭切换开关,在中间过渡状态
期间(就在过渡开始之后)将始终是:可见的 ,因此它总是返回 true。
但是如果您在调用 slideToggle 之前使用 .is(":visible")
。然后我们可以利用结构的功能:
$( "#bases" ).click(function() {
var visibility = $('.bases').is(':visible');
if(visibility){
console.log ("not visible");
}
else {
console.log ("visible")
}
$( ".bases" ).slideToggle( "slow");
});
现在,您可能会注意到条件似乎有问题。
为什么可见性变量设置为true时日志记录不可见?
那是因为就像我说的,在切换幻灯片之前或过渡期间,您必须记录它。因此,当它实际上不可见
并且您单击该按钮时,它将记录可见并切换内容以显示
,反之亦然。
if ($(".bases, .protein, .toppings, .sauces, .extratoppings, .teas, .desserts").is(":visible")) {
$(".bases, .protein, .toppings, .sauces, .extratoppings, .teas, .desserts").hide();
}
$("#bases").click(function() {
var visibility = $('.bases').is(':visible');
if (visibility) {
console.log("not visible");
} else {
console.log("visible");
}
$(".bases").slideToggle("slow");
});
$("#protein").click(function() {
$(".protein").slideToggle("slow");
});
$("#toppings").click(function() {
$(".toppings").slideToggle("slow");
});
$("#sauces").click(function() {
$(".sauces").slideToggle("slow");
});
$("#extratoppings").click(function() {
$(".extratoppings").slideToggle("slow");
});
$("#teas").click(function() {
$(".teas").slideToggle("slow");
});
$("#desserts").click(function() {
$(".desserts").slideToggle("slow");
});
html {
height: 100%;
}
body {
display: flex;
flex-direction: column;
height: 100vh;
/* Avoid the IE 10-11 `min-height` bug. */
}
.content {
flex: 1 0 auto;
/* Prevent Chrome, Opera, and Safari from letting these items shrink to smaller than their content's default minimum size. */
padding: 20px;
}
.footer {
flex-shrink: 0;
/* Prevent Chrome, Opera, and Safari from letting these items shrink to smaller than their content's default minimum size. */
padding: 20px;
}
a {
text-decoration: none;
color: white;
}
* {
box-sizing: border-box;
}
body {
margin: 0;
font: 16px Sans-Serif;
}
h1 {
margin: 0 0 20px 0;
}
p {
margin: 0 0 20px 0;
}
footer {
background: #42A5F5;
color: red;
}
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td,
th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
ul,
li {
text-decoration: none;
list-style: none;
margin: 3%;
margin-bottom: 5%;
width: auto;
}
#menuitems {
display: flex;
width: auto;
margin: 0%;
margin-bottom: 5%;
align-items: center;
justify-content: center;
background: blue;
color: white;
text-decoration: none .caloriecalculatormain {
display: none !important;
}
<!DOCTYPE html>
<html>
<head>
<title>Padthai calc</title>
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body>
<div class="content">
<h1>PADTHAI CALORIE CALCULATOR</h1>
</div>
<ul id="menuitems">
<li><button id="bases">Main Dish</button></li>
<li><button id="protein">Soup</button></li>
<li id="teas"><button>Teas</button></li>
<li id="desserts"><button>Desserts</button></li>
</ul>
<div>
<div class="bases">
<h1>Main Dish</h1>
<table>
<tr>
<th>Company</th>
<th>Contact</th>
<th>Country</th>
</tr>
<tr>
<td>Alfreds Futterkiste</td>
<td>Maria Anders</td>
<td>Germany</td>
</tr>
<tr>
<td>Centro comercial Moctezuma</td>
<td>Francisco Chang</td>
<td>Mexico</td>
</tr>
<tr>
<td>Ernst Handel</td>
<td>Roland Mendel</td>
<td>Austria</td>
</tr>
<tr>
<td>Island Trading</td>
<td>Helen Bennett</td>
<td>UK</td>
</tr>
<tr>
<td>Laughing Bacchus Winecellars</td>
<td>Yoshi Tannamuri</td>
<td>Canada</td>
</tr>
<tr>
<td>Magazzini Alimentari Riuniti</td>
<td>133</td>
<td>152</td>
</tr>
</table>
</div>
<div class="protein">protein</div>
<div class="toppings">toppings</div>
<div class="sauces">sauces</div>
<div class="extratoppings">extratoppings</div>
<div class="teas">teas</div>
<div class="desserts">Desserts</div>
</div>
</body>
</html>
<style>
</style>
<footer class="footer">
<div id="total">Total</div>
<div id="carbs">Carbs</div>
</footer>
</body>
</html>
关于javascript - JQuery 滑动开关 :visible conditional,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47920412/
现在我已经创建了一个额外的跨度来容纳一个条件。 568 || subKey == 0" ng-repeat="links in linksWrap.links">
一些 excel IF 语句可能会变得相当长,我正在寻找一种更简单的方法来编写它们。例如,如果我要写: If($B$4+13=7,$B$4+13,FALSE) 我认为它会更容易说: If($B$4+1
我有一个包含 FromDate 、 ToDate 、 VendorName 和 GoodsName 的表单,一旦一切为真,我需要显示结果 示例: FromDate="11/20/2019"、ToDat
我经常看到使用 !!condition 而不仅仅是常规条件的代码。即: if(!!value){ doSomething(); } 对比: if(value){ doSomething
这个问题有点模棱两可,这两个在汇编代码/性能方面是否等效: public void example{ do{ //some statements; if(condition)
在我看到的使用 Any 方法的 Linq 查询示例中,大约有一半是通过将其应用于 Where() 调用的结果来实现的,另一半则直接将其应用于集合。这两种样式是否总是等效的,或者在某些情况下它们可能会返
这个问题在这里已经有了答案: What does !!(x) mean in C (esp. the Linux kernel)? (3 个答案) 关闭 9 年前。 我见过人们使用带有两个 '!'
我对部署在生产环境中的应用程序进行了线程转储,该应用程序使用 logback。我不是分析线程转储的专家,但是,我必须这样做。正在学习,网上也看了一些文章。 下面是真正的线程转储: "logback-8
在 SQL 中(特别是 Postgres): 子句 where not foo='bar' in case foo is null 评估为某种 null,导致该行不是包含在结果中。 另一方面,子句 w
是不是类似于has and condition with join和where condition after join? 例如 对于以下两个查询,它会给我相同的结果吗 1) SELECT COUNT
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
如果您调用某个函数,并且该函数在发生错误时返回 NULL(例如,想想 malloc() 或 fopen()),两个更好: FILE *fp = fopen(argv[0], "r"); if (fp
我正在使用 Azure 数据工厂 V2,我需要在父检查验证中实现两级检查。例如:如果条件一为真,那么我需要检查条件 2。并且,如果条件 2 为真,则检查条件 3。 这是一种分层检查。当我在父 IF 条
使用 Linq to Entities 有以下区别吗? db.EntityName.Where(a => a.Id == id).FirstOrDefault(); db.EntityName.Fir
我有一种情况,我已经用两种不同的方式解决了,但想知道人们对这些选项的看法,以及他们是否有其他选择...... 系统正在处理数据的“间隔”。 所有数据都分配到一个“区间” 该间隔由事实表 中的“inte
我有包含字段 Amount, Condition1, Condition2 的表格。 例子: Amount Condition1 Condition2 ---------------------
我正在尝试在 Netbeans 中制作一个简单的 MySQL、Java JDBC Web 应用程序。我希望根据当前 session 中的状态变量显示不同的内容。我尝试了以下方法: 首先,我在 .jsp
我想为 postnuke cms 设计一个主题。 并希望在模板文件中使用 css 条件。 postnuke 使用类似 smarty 的标签 .... 所以当我使用 .... 它给出了一些关于标签的错误
我想问一下asyncio.Condition .我对这个概念并不熟悉,但我从学生时代就知道并了解锁、信号量和队列。 我找不到很好的解释或典型的用例,只是 this example .我看了看来源。核心
我想知道如何在不在语句中重做相同查询两次的情况下处理 SQL 比较。这是我要找的: SELECT columnName10, IF( SELECT columnName20 FROM Othe
我是一名优秀的程序员,十分优秀!