jQuery - 将值插入<input value =“”/>

时间:2014-12-24 09:42:04

标签: jquery

我有以下脚本,它使用其他输入元素的值动态构建文本字段。 该值显示在屏幕上,但在开发工具中检查时,它不会插入value=""。我需要将值插入为value="",以便可以保留表单数据。

$(document).on('click', 'button', function(event) {
  $("fieldset").append($('<input>').prop('type', 'text').val($('#entry').val()));
});

See my image

2 个答案:

答案 0 :(得分:2)

您需要使用.attr()

使用:

 $('<input>').attr('value', $('#entry').val())

答案 1 :(得分:2)

$(document).on('click', 'button', function(event) {
    $("fieldset").append($("input[type = 'text']")).val($('#entry').val());
    });

希望这会对你有所帮助。

相关问题