- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一些代码基本上是 3 个按钮和 3 个隐藏的轮播。当您将鼠标悬停在一个按钮上时,它会预览它的旋转木马,当您单击它时,它会显示旋转木马。
为了禁用悬停预览效果以在点击时隐藏轮播,我使用了代码:$(this).data('pinned', !$(this).data('pinned'));
并且它有效,但我不确定为什么。谁能解释为什么它一直显示轮播?
$('#button01')
.hover(function() {
if (!($(this).data('pinned')) && !($(this).hasClass('disabled'))) {
$('#carousel01').toggle('slide');
}
})
.click ( function () {
// cancel hover effect and pin carousel
$(this).data('pinned', !$(this).data('pinned'));
// disable other options
if (!($(this).hasClass('disabled'))) {
$(this).toggleClass('btn-primary');
$('#button02').toggleClass('disabled');
$('#button03').toggleClass('disabled');
}
});
我希望 .data('pinned')
函数只应用于按钮。它适用于整个可见页面吗?我试图查找它,但我看不到有关将“固定”与 .data() 函数一起使用的任何信息。
我最初从这里得到代码:Unpinning a div on document click
相关的 HTML:
<div class="jumbotron">
<div class="container">
<div class="col-md-4">
<img src="" class="btn btn-default btn-lg displayed" id="button01" href="#" height="175" width="175">
<p class="centered"></p>
</div>
<div class="col-md-4">
<img src="" class="btn btn-default btn-lg displayed" id="button02" href="#" height="175" width="175">
</div>
<div class="col-md-4">
<img src="" class=" btn btn-default btn-lg displayed" id="button03" href="#" height="175" width="175">
</div>
</div>
</div>
</div>
<div class="container">
<div id="carousel01" class="carousel slide wizard">
<div class="carousel-inner" role="listbox">
<div class="item active">
<h2>Slide 01<br />
<small>subheading</small></h2>
<p>Lorem ipsum </p>
<a class="btn btn-primary" href="#carousel01" role="button" data-slide="next">Continue</a>
</div>
<div class="item">
<h2>Slide 02<br />
<small>subheading</small></h2>
<p>Lorem ipsum</p>
<a class="btn btn-primary" href="#carousel01" role="button" data-slide="next">Next</a>
</div>
<div id="carousel02" class="carousel slide wizard">
<div class="carousel-inner" role="listbox">
<div class="item active">
<h2>Slide 01<br />
<small>subheading</small></h2>
<p>Lorem ipsum </p>
<a class="btn btn-primary" href="#carousel02" role="button" data-slide="next">Continue</a>
</div>
<div class="item">
<h2>Slide 02<br />
<small>subheading</small></h2>
<p>Lorem ipsum</p>
<a class="btn btn-primary" href="#carousel02" role="button" data-slide="next">Next</a>
</div>
...
最佳答案
让我们分析下面的代码:
$('#button01') // The button's jQuery Object.
.click ( function () { // Click event handler binding.
$(this).data('pinned', !$(this).data('pinned')); // this refers to the <input />
});
$(this).data()
函数获取 data-
来自 <input />
的属性.
$(this).data('pinned')
获取 data-pinned
的值值(value)。
现在,它可以是任何东西。它将在 string
中返回格式。因此,当值类似于:true
:
$(this).data('pinned', !$(this).data('pinned'));
这变成了false
.它仅用于类型转换。这在 JavaScript 和其他编程语言中很常见,您可以说这是将任何类型的变量转换为 boolean
的快捷方式。 .
所以,当你有类似字符串的东西时:
var a = "true"; // string: true
b = !a; // bool: false;
c = !!true; // bool: true
希望它是清楚的。上面的代码在 data-pinned
的 true 和 false 之间切换。单击时的属性。
Note: As people have said in the comments: Note that
.data()
does not only checks for the HTMLdata-
attribute, but also looks within the jQuerydata
object for the selected element(s).
关于javascript - JQuery:$(this).data ('pinned' ) 实际上做了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32168147/
我有一个关于 JavaScript 语法的问题。实际上,我在自学 MEAN 堆栈教程时想出了编码(https://thinkster.io/mean-stack-tutorial#adding-aut
在我的书中它使用了这样的东西: for($ARGV[0]) { Expression && do { print "..."; last; }; ... } for 循环不完整吗?另外,do 的意义何
我已经编写了读取开关状态的代码,如果按 3 次 # 则退出。 void allkeypadTest(void) { static uint8_t modeKeyCount=0; do
因此,对于上周我必须做的作业,我必须使用 4 个 do-while 循环和 if 语句在 Java 中制作一个猜谜游戏。我无法成功完成它,类(class)已经继续,没有为我提供任何帮助。如果有人可以查
int i=1,j=0,n=10,k; do{ j+=i; i<<1; printf("%d\n",i); // printf("%d\n",12<<1); }while
此代码用于基本杂货计算器的按钮。当我按下按钮时,一个输入对话框会显示您输入商品价格的位置。我遇到的问题是我无法弄清楚如何获得 do ... while 循环以使输入对话框在输入后弹出。 我希望它始终恢
当我在循环中修改字符串或另一个变量时,它的条件是否每次都重新计算?或者在循环开始前一次 std::string a("aa"); do { a = "aaaa"; } while(a.size<10)
我刚刚写了这个,但我找不到问题。我使用代码块并编写了这个问题 error: expected 'while' before '{' token === Build finished: 1 errors
do { printf("Enter number (0-6): ", ""); scanf("%d", &Num); }while(Num >= 0 && Num 表示“超过”,<表
我有一个包含 10 个项目的 vector (为简单起见,所有项目都属于同一类,称其为“a”)。我想要做的是检查“A”不是 a) 隐藏墙壁或 b) 隐藏另一个“A”。我有一个碰撞函数可以做到这一点。
嗨,这是我的第二个问题。我有下表 |-----|-------|------|------| |._id.|..INFO.|.DONE.|.LAST.| |..1..|...A...|...N..|.
这个问题在这里已经有了答案: 关闭 12 年前。 Possible Duplicates: Why are there sometimes meaningless do/while and if/e
来自 wikibook在 F# 上有一小部分它说: What does let! do?# let! runs an async object on its own thread, then it i
我在 Real World Haskell 书中遇到了以下函数: namesMatching pat | not (isPattern pat) = do exists do
我有一个类似于下面的用例,我创建了多个图并使用 gridExtra 将它们排列到一些页面布局中,最后使用 ggsave 将其保存为 PDF : p1 % mutate(label2
当我使用具有 for 循环的嵌套 let 语句时,如果没有 (do (html5 ..)),我将无法运行内部 [:tr]。 (defpartial column-settings-layout [&
执行 vagrant up 时出现此错误: anr@anr-Lenovo-G505s ~ $ vagrant up Bringing machine 'default' up with 'virtua
# ################################################# # Subroutine to add data to the table Blas
我想创建一个检查特定日期格式的读取主机。此外,目标是检查用户输入是否正确,如果不正确,则提示应再次弹出。 当我刚接触编程时,发现了这段代码,这似乎很合适。我仍然在努力“直到” do {
我关注这个tutorial在谷歌云机器学习引擎上进行培训。我一步一步地跟着它,但是在将 ml 作业提交到云时我遇到了错误。我运行了这个命令。 sam@sam-VirtualBox:~/models/r
我是一名优秀的程序员,十分优秀!