在嵌套列表上应用 jquery-ui droppable
我正在尝试在嵌套列表上使用 jquery droppable,对悬停时 li 的背景颜色进行更改。问题是它仅适用于列表中的第一项。不过,警报仍然会警告列表项中的文本。有什么想法为什么会发生这种情况吗?
$("#mailbox li").droppable({
greedy: true,
hoverClass: 'mailbox-hover',
drop: function(event, ui) {
alert($(this).text());
}
});
[编辑] 在某些测试中,警报工作正常,正在应用悬停类(根据 fireBug),但当我将鼠标悬停在第一个元素上时,它只会更改文本颜色。
<ul id="mailbox" class="filetree">
<li>
<span class="folder">[email protected]
</span>
<ul>
<li id="0-INBOX">
<span class="folder">
</span>
<a href="#" onclick="changeFolder('0', 'INBOX', 'INBOX');" name="INBOX">INBOX
</a>
<ul>
<li id="0-INBOX-Drafts">
<span class="file">
</span>
<a href="#" onclick="changeFolder('0', 'INBOX.Drafts', 'Drafts');" name="INBOX.Drafts">Drafts
</a>
<li id="0-INBOX-Sent">
<span class="file">
</span>
<a href="#" onclick="changeFolder('0', 'INBOX.Sent', 'Sent');" name="INBOX.Sent">Sent
</a>
<li id="0-INBOX-Trash">
<span class="folder">
</span>
<a href="#" onclick="changeFolder('0', 'INBOX.Trash', 'Trash');" name="INBOX.Trash">Trash
</a>
<ul>
<li id="0-INBOX-Trash-New">
<span class="file">
</span>
<a href="#" onclick="changeFolder('0', 'INBOX.Trash.New', 'New');" name="INBOX.Trash.New">New
</a>
</ul>
</ul>
</ul>
</li>
[css 是注释] - 另外,可能相关,可能是 css 错误,它不会让我设置悬停时 li 的背景颜色,只能设置字体颜色。
.mailbox-hover
{
background-color: #0000ff;
}
.mailbox-dropped
{
color: #ffff00;
}
[已解决] - 最后,即使所有列表项都附加了 id,它也不会让我发出警报 ($(this).id)。
I am trying to use jquery droppable on a nested list, applying a change to the background colour of the li on hover. The problem is that it is only applying to the first item in a list. The alert is still alerting the text within the list item though. Any ideas why this would be happening?
$("#mailbox li").droppable({
greedy: true,
hoverClass: 'mailbox-hover',
drop: function(event, ui) {
alert($(this).text());
}
});
[Edit]
On some testing, the alert is working right, the hover class is being applied (according to fireBug) but it will only change the text-color when I hover over the first element.
<ul id="mailbox" class="filetree">
<li>
<span class="folder">[email protected]
</span>
<ul>
<li id="0-INBOX">
<span class="folder">
</span>
<a href="#" onclick="changeFolder('0', 'INBOX', 'INBOX');" name="INBOX">INBOX
</a>
<ul>
<li id="0-INBOX-Drafts">
<span class="file">
</span>
<a href="#" onclick="changeFolder('0', 'INBOX.Drafts', 'Drafts');" name="INBOX.Drafts">Drafts
</a>
<li id="0-INBOX-Sent">
<span class="file">
</span>
<a href="#" onclick="changeFolder('0', 'INBOX.Sent', 'Sent');" name="INBOX.Sent">Sent
</a>
<li id="0-INBOX-Trash">
<span class="folder">
</span>
<a href="#" onclick="changeFolder('0', 'INBOX.Trash', 'Trash');" name="INBOX.Trash">Trash
</a>
<ul>
<li id="0-INBOX-Trash-New">
<span class="file">
</span>
<a href="#" onclick="changeFolder('0', 'INBOX.Trash.New', 'New');" name="INBOX.Trash.New">New
</a>
</ul>
</ul>
</ul>
</li>
[css is comments] - Also, possibly related, possibly a css error, it won't let me set the background-color of the li on hover, only font color.
.mailbox-hover
{
background-color: #0000ff;
}
.mailbox-dropped
{
color: #ffff00;
}
[solved] - And finally, it won't let me alert ($(this).id) even though the all the list items have an id attached.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是为了警报:
这是为了CSS:
在我们处理...更简单的格式化过程中,我将继续更新这个答案。
This for alert:
This for CSS:
I'll continue to update this answer while we work through...easier formatting here.
我对嵌套掉落物品的解决方案:
My solution to nesting dropped items: