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 回答