一起使用html()和replaceWith()

时间:2014-01-26 18:15:32

标签: jquery html replacewith

我想用另一个div替换一个div,同时这样做我想用从第一个div读取的值填充第二个div

所以我猜我应该同时使用它们但它不起作用。 这是我正在使用的代码:

$("#test1").replaceWith($("#register p").html(programType).show()); 

寄存器div是:

<div id="register" style="display: none;">
    <div class="row">
        <div class="span4">
            <div class="field row">
                <div class="fieldName span0">Program : </div>
                <p>{{programType}}</p>
            </div>
        </div>
    </div>
</div>

所以不要得到:程序:programType的值 我只得到: programType的值

2 个答案:

答案 0 :(得分:0)

您正在引用寄存器中的 p 标记。那为你收到 programType的值

答案 1 :(得分:0)

你可能想要像

这样的东西
$("#test1").replaceWith($("#register")).show().find("p").html(programType);

目前还不清楚你想要执行什么,因为不清楚什么是#test1你的意思是什么而不是得到:程序:programType的值我只得到:programType的值“

相关问题