我目前正在尝试通过javascript构建一些html,当我尝试分配我的textarea输入控件的value属性时,它似乎不想通过,textarea在加载时变为空白。对于普通文本类型输入,值似乎可以通过。我还介绍了javascript代码,并确保我获得的JSON数据实际上有一个值,就是这样。
function BuildDeviceInfoHTML(data) {
var divFormGroupOpening = '<div class="form-group">';
var divOpeningInput = '<div class="col-md-10">'
var result;
var deviceName = divFormGroupOpening + '<label class="col-md-2 control-label" for="deviceName">Device Name: </label>' +
divOpeningInput +
'<input id="deviceName" class="form-control" type="text" value="' + data.devices[0].deviceName + '" name="deviceName" data-val-required="Device name is required" data-val="true">'
+ '</div></div>';
var deviceDisplay = divFormGroupOpening + '<label class="col-md-2 control-label" for="deviceDisplay">Displayed as: </label>' +
divOpeningInput +
'<input id="deviceDisplay" class="form-control" type="text" value="' + data.devices[0].deviceDisplay + '" name="deviceDisplay" data-val="false">'
+ '</div></div>';
var deviceDesc = divFormGroupOpening + '<label class="col-md-2 control-label" for="deviceDisplay">Displayed as: </label>' +
divOpeningInput +
'<textarea id="deviceDesc" class="form-control" value="' + data.devices[0].deviceDesc + '" name="deviceDesc" data-val="false"></textarea>'
+ '</div></div>';
result = deviceName + deviceDisplay + deviceDesc;
return result
}
答案 0 :(得分:2)
Textarea没有value
属性。您应该将内容放在标记内:
<textarea>VALUE HERE</textarea>
您应该修改代码的最后部分:
var deviceDesc = divFormGroupOpening +
'<label class="col-md-2 control-label" for="deviceDisplay">
Displayed as: </label>' + divOpeningInput +
'<textarea id="deviceDesc" class="form-control" name="deviceDesc"
data-val="false">' + data.devices[0].deviceDesc + '</textarea>'
+ '</div></div>';