动态创建一个表单
问题描述:
我有这样的:动态创建一个表单
$('input[data-type="UserDetails"]').each(function(index, input){
var name = $(input).attr('name');
var value = $(input).is(":checked");
alert('name: ' + name + ' value:' + value);
});
showForm = "<form><fieldset><legend>Headline here</legend><label>Name</label><input type='text' class='input-fluid' name='txtName'><label class='checkbox'><input type='checkbox'> Accept Terms & Conditions</label><button type='submit' class='btn'>Send</button></fieldset></form>";
的第一件事是做的是检查是检查其复选框。取决于我想将它们添加到表单。就像“选中文本字段的复选框”一样。如何最聪明的方式将它们添加到“showForm”形式?
我可以在“showForm”中使用true/false语句吗?在这种情况下如何使用它?
感谢您的帮助!
答
预先制作好表格并给它一个display: none
。一旦你有了这个,实现下面的功能。
$('input[data-type="UserDetails"]').each(function(index, input){
var name = $(input).attr('name');
if($(input).is(":checked")){
$("form").append('<input type="text" value="' + value + '" />');
}
});
$("form").show(); // Show the form
建立一个表格在一条线...... * cringe!* – 2013-04-28 13:46:22
@Evan Yep,为什么不能在一行中创建一个完整的网站? o_O – 2013-04-28 14:11:55