1

我有一些这样的 HTML 设置:

<div>
    <label for="amount"><a id="amount-help-icon" class="help icon-link" href="#"><span class="ui-icon ui-icon-help"></span></a> Amount:</label>
    <input id="amount" class="inputText" type="text" value="" maxlength="100" size="10" name="amount" />
    <span class="help">The amount for stuff</span>
</div>

我试图让 jquery 在单击帮助图标时显示一个对话框,所以我有这个:

$("a.help").click(function () {
    $(this).closest("label").siblings(".help").dialog({ title: "Help" });
    return false;
});

第一次显示对话框效果很好,但是当我单击图标时,跨度从 DOM 中消失了。因此,如果我再次单击该图标,则什么也不会发生(因为没有 span.help 可查找)。

4

2 回答 2

1

您可能想要克隆跨度。

$(this).closest("label").siblings(".help").clone().dialog({ title: "Help" });
于 2010-10-14T15:51:00.680 回答
1

以下允许您多次重复使用该对话框 - 但它<span>会立即消失,而不是在第一次单击时消失。

$("a.help").each(function(i, link) {
    var $this = $(this), 
        d = $this.closest("label").siblings(".help").dialog({ title: "Help", autoOpen: false });
    $this.data('dialog', d);
});

$("a.help").click(function () {
    $(this).data('dialog').dialog('open');
    return false;
});​

演示在这里

于 2010-10-14T15:52:41.517 回答