0

リンク: http://jsfiddle.net/7GGeX/24/

リンクを 1、2、3 の順にクリックすると、私が混乱している理由がわかります。

replaceWith 内で関数を使用すると、置換の配置が無効になりますか?

$(document).ready(function () {
    $(".click1").click(function () {
        $("#one").replaceWith(function () {
            $('#replace1').show();
        });
        return false;
    });

助けてくれてありがとう!

4

1 に答える 1

2

return置換として使用する値が必要です。

$("#two").replaceWith(function() {
      // return the element
    return $('#replace2').show();
});

または関数を渡さないでください:

$("#two").replaceWith($('#replace2').show());

明示的に何も返さなかったので、replacediv が表示されてundefinedから返され、元のものを効果的に何も置き換えませんでした。

于 2010-12-14T02:23:16.917 に答える