我想.text()从选中的输入中获取标签。实际上,我的代码检查是否检查了输入,然后从每个<li>具有相同类的对象(不仅是检查的对象)中获取标签。我该如何实现?我认为我应该使用.parent()或.child()属性,但我不知道如何使用。
我尝试过alert($('#myId input').parent('label').text());但没有成功。
Codepen https://codepen.io/Qasph/pen/LyNJev?editors=1010
$('#result').click(function() {
// If an input is checked
if ($('#myId input').is(':checked')) {
// Get text from label parent
console.log($('#myId label').text());
} else {}
});Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="myId">
<ul>
<!-- First class -->
<li class="myFirstClass"><label><input type="checkbox" value="3">1 - First class</label></li>
<li class="myFirstClass"><label><input type="checkbox" value="6">2 - First class</label></li>
<!-- Second class -->
<li class="mySecondClass"><label><input type="checkbox" value="3">1bis - Second class</label></li>
<li class="mySecondClass"><label><input type="checkbox" value="6">2bis - Second class</label></li>
</ul>
</div>
<button id="result">Result</button>Run Code Online (Sandbox Code Playgroud)
当我尝试设置animation.fillMode = kCAFillModeForwardsXcode时无法编译并显示错误." 使用未解析的标识符'kCAFillModeForwards'".
我已经在以前的项目中使用过这个没有任何问题,有人已经遇到过这种行为吗?
func animateGradient() {
currentGradient += 1
let animation = CABasicAnimation(keyPath: Animation.keyPath)
animation.duration = animationDuration
animation.toValue = currentGradientSet()
animation.fillMode = kCAFillModeForwards
animation.isRemovedOnCompletion = false
animation.delegate = self
gradient.add(animation, forKey: Animation.key)
}
Run Code Online (Sandbox Code Playgroud)