我正在jQuery中编写一个可排序的列表实现(b/c臭名昭着的scroll-in-div问题,对此有什么新的解决方案吗?).但是,我不知道如何比较jQuery包装后的元素(在mousedown/mouseup上触发).在原型中,它始终是ele.domNode.
这就是我想要实现的......
<div id="cheese"></div>
<div id="burger"></div>
<script>
// Some dom nodes wrapped in jquery
var ele1 = $('#cheese');
var ele2 = $('#burger');
var ele3 = $('#burger');
// Is the dom node wrapped in ele1 (#cheese) the same as in ele2 (#burger)?
if (ele1 == ele2)
{
// Should never be true
}
// Is the dom node wrapped in ele2 (#burger) the same as in el32 (#burger)?
if (ele2 == ele3)
{
// Should always be true
}
</script>
Run Code Online (Sandbox Code Playgroud) 我需要将一个元素传递给一个函数,然后在遍历父元素时匹配该特定元素.捕获(对于像我这样无能为力的人)是这个元素没有id.在下面的示例中,我希望每个元素都变为粉红色,除非单击的元素变为黄色
function colorize(element) {
element.parent().find('span').each(function() {
if ($(this)===element) { // the problem is this is always false
$(this).css('background','yellow');
} else {
$(this).css('background','pink');
}
});
}
$('span').click(function() {
colorize($(this));
});
Run Code Online (Sandbox Code Playgroud) 我试图检查一个contenteditable元素是否被聚焦(它有闪烁的插入符号),但这不起作用:
cy.get('span[contenteditable]').then($span => {
cy.focused().then($focused => {
expect($focused).to.eql($span)
}
}
Run Code Online (Sandbox Code Playgroud)
我应该怎么做?