<div class="a-1">
<div class="a-2">
<div class="a-3">
<div class="a-1 a-2">
<div class="a-2 a-3">
<div class="a-1 a-3">
<div class="a-1 a-2 a-3">
Run Code Online (Sandbox Code Playgroud)
我希望做这样的事情:
$('.a-1').show().siblings([all those that do not belong to a-1]).hide();
Run Code Online (Sandbox Code Playgroud)
反正有没有实现这个目标?的:not()选择似乎是失败的我,因为它选择的逆每个元素单独,导致选择的所有7倍的DIV.
(function() {
// ...
// ...
}());
Run Code Online (Sandbox Code Playgroud)
这种模式的具体含义是什么?请注意,它不是自调用函数(function() {})();
例如:
$.get('/path/to/api').then(
function(data) {
alert( "$.get succeeded" );
}, function(error) {
alert( "$.get failed!" );
}
);
Run Code Online (Sandbox Code Playgroud)
是否可以在两个回调中应用回调运算符?
请考虑以下示例:
if (cache) {
x = cache;
} else {
x = cache = someMethod();
}
Run Code Online (Sandbox Code Playgroud)
无论如何要让它短于cache ? x = cache : x = cache = someMethod();?
编辑:
感谢所有提议的解决方案,我应该注意到有问题的数据是字符串而不是布尔值.
是否有任何方法可以传递this到立即调用的函数表达式,而无需解析var that = this(在某些情况下不适用)?
试过以下但没有运气:
(function(that) {
console.log(that);
})(this)
Run Code Online (Sandbox Code Playgroud) 假设我有以下输出整数的基本循环:
for (var i = 0; i < 6; i++) {
echo i;
}
/* Output: 0 1 2 3 4 5 */
Run Code Online (Sandbox Code Playgroud)
是否有可能将其输出"翻转"为5 4 3 2 1 0使用一个简单的变量flag,其值只能是1或-1不使用if/else?
主要是在JavaScript中寻找答案,但这应该是一个与语言无关的问题.