【发布时间】:2016-08-17 13:14:49
【问题描述】:
我正在单击一个按钮以调出一个引导模式,其中包含一个动态创建的表单。我的问题是输入字段始终被视为文本,即使它们设置为其他内容,例如选择、只读或数字。
Here you can see that the inputs have the right type-values, but the inputs are textfields anyway.
此处创建表单(console.log的输出如图):
var data = "";
data += "<form name='altEditor-form' role='form'>";
for(var j = 0; j < columnDefs.length; j++){
//Outputting input title and input.type
console.log(j + ": " + columnDefs[j].title + " - " + columnTypes[j].type)
data += "<div class='form-group'><div class='col-sm-3 col-md-3 col-lg-3 text-right' style='padding-top:7px;'><label for='" + columnDefs[j].title + "'>" + columnDefs[j].title + ":</label></div><div class='col-sm-9 col-md-9 col-lg-9'><input type='" + columnTypes[j].type + "' id='" + columnDefs[j].title + "' name='" + columnDefs[j].title + "' placeholder='" + columnDefs[j].title + "' style='overflow:hidden' class='form-control form-control-sm' value='" + adata.data()[0][newaData[j].name] + "'></div><div style='clear:both;'></div></div>";
}
data += "</form>";
如您所见,我将输入类型设置为:
<input type='" + columnTypes[j].type + "' ....
然后在此处将表单添加到模态:
$('#altEditor-modal').find('.modal-body').html(data);
我无法理解它。类型怎么可能被完全忽略?
【问题讨论】:
-
为什么是
pre?我怀疑这会使您的标记失效。 -
readonly 不是输入的有效值。您可以添加“readonly”字样。w3schools.com/tags/att_input_readonly.asp
-
@JeremyThille 看起来他正试图将
data的输出呈现为html -
这就是我的观点。数据是 html,但
pre标签将其中和并阻止浏览器解释其中的 html。 -
@JeremyThille 我正在编辑其他人创建的代码,所以这是他工作的残余。我尝试将其更改为
<div>并同时删除所有标签,但问题是一样的。
标签: javascript jquery forms