[英]Generate input field using jQuery's append
Issue: I am attempting to append an input field from a modal window, containing a value inserted by the user, to an existing panel. 问题:我试图将模态窗口中的输入字段(包含用户插入的值)附加到现有面板。 So far the user is able to create the new field from the modal and add it, however, as this is part of an edit page, I want their input to be added to an input field.
到目前为止,用户已经可以从模式中创建新字段并将其添加,但是,由于这是编辑页面的一部分,因此我希望将其输入添加到输入字段中。 Here is the working code: BOOTPLY EXAMPLE .
这是工作代码: BOOTPLY示例 。 I want the newly generated field to be formatted the same as the existing fields because it will become part of a giant form allowing it to be submitted and update the operational page.
我希望将新生成的字段的格式设置为与现有字段相同的格式,因为它将成为允许提交并更新操作页面的巨型表单的一部分。
Question: Will I have to format this within the append function itself where I declare the other formatting constraints? 问题:我是否必须在声明其他格式化约束的附加函数本身中对此进行格式化? or can I somehow set the attributes within the 'cloudcontainer' div where the input is being appended to?
还是可以以某种方式在输入附加到的“ cloudcontainer” div中设置属性? Also, should I be using .html function instead of append?
另外,我应该使用.html函数而不是append吗? Performance is really not a concern here.
在这里,性能确实不是问题。
Thanks 谢谢
You have to append exactly same formatted input
tag as you have generated in the beginning and then add the form value to it 您必须添加与开始时生成的格式完全相同的
input
标签,然后向其中添加表单值
$("#clickme").click(function(){
$('.cloudcontainer').append('<div class="cloud"><p><b>'+$('#fieldtitle').val()+': </b><input style="display: inline; width: 325px;" class="form-control" id="projectName" type="text" value="'+$('#fieldvalue').val()+'" </input></p></div>');
});
在您的JavaScript中,在添加字段的行上您应该执行以下操作:
$('.cloudcontainer').append('<div class="cloud"><p><b>'+$('#fieldtitle').val()+': </b>'+'<input type="text" value="' + $('#fieldvalue').val() + '"></p></div>');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.