1

它只工作了几秒钟,然后 div 再次消失:

$(document).ready(function () {

    $("#done").click(function () {
        $('#txtname').replaceWith(function () {

            return '<div>' + $(this).val() + '</div>';
        });
    });
4

1 回答 1

0

ID如果this不起作用,您也可以使用

$("#done").click(function() {
    $('#txtname').replaceWith(function() {

        return '<div>' + $("#txtname").val() + '</div>';
    });
});

如果上述方法不起作用,这是另一个示例

$("#done").click(function() {
    $('#txtname').replaceWith('<div>' + $("#txtname").val() + '</div>');
});
于 2012-09-23T11:29:56.527 回答