我正在尝试为 Google 地图创建一个信息窗口,并且需要生成一个动态表单来显示信息。
以下脚本会生成一个名为"No_found_err: DOM exception 8"的错误:
//create objects for HTML elements
var inputElement1 = document.createElement("input");
var inputElement2 = document.createElement("input");
//assign different attributes to the element
inputElement1.setAttribute("type", "text");
inputElement1.setAttribute("id", "poiName");
inputElement2.setAttribute("type", "textarea");
inputElement2.setAttribute("id", "poiDesc");
//create style tag, atrributes and values
//add css style to head tag and define classname for HTML "desctag" element
var cssNode = document.createElement("style");
cssNode.setAttribute("type", "text/css");
cssNode.style.cssText = ".cssClass {vertical-align: text-top; width: 250px; height: 150px }";
document.getElementsByTagName("head")[0].appendChild("cssNode");
document.getElementById("poiDesc").className = "cssClass";
var formString = "<b>Enter location details:</b>
<p>Name: " +
" " + inputElement1 + "<br>Description: " + inputElement2 +
"<p><center>" + "<input type='button' id='saveBtn' value='Save' onclick='savePOI()'>
</center>";
//insert values into the form elements
document.getElementById("poiName").value = locList[i].name;
**document.getElementById("poiDesc").value = locList[i].desc;**
此错误出现在最后两行之间。这是否意味着尚未创建标签 ID“poiName”和/或“poiDesc”?
我该如何解决上述问题?
谢谢你。