jQuery - 在函数调用中使用当前对象
jQuery - using current object in a function call
我想让这段代码正常工作,但是 .css 函数正在返回 undefined
$(".split-section-headings .ssh-cell")
.html("This container has padding-top = " + $(this).css("paddingTop") );
谢谢!
如果没有类似于 .each()
的东西或在事件处理程序中,您不能使用 $(this)
:
$(".split-section-headings .ssh-cell").each(function() {
$(this).html("This container has padding-top = " + $(this).css("padding"));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="split-section-headings">
<div class="ssh-cell"></div>
</div>
我想让这段代码正常工作,但是 .css 函数正在返回 undefined
$(".split-section-headings .ssh-cell")
.html("This container has padding-top = " + $(this).css("paddingTop") );
谢谢!
如果没有类似于 .each()
的东西或在事件处理程序中,您不能使用 $(this)
:
$(".split-section-headings .ssh-cell").each(function() {
$(this).html("This container has padding-top = " + $(this).css("padding"));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="split-section-headings">
<div class="ssh-cell"></div>
</div>