javascript 元素的内容必须由格式良好的标记组成

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8386945/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 03:16:49  来源:igfitidea点击:

Content of elements must consist of well-formed mark-up

javascript

提问by Cecil Rodriguez

So I was asking a question on here, got around to implementing the solution, and it doesn't seem to work particularly well - I keep getting the error "content of elements must consiste of well-formed mark-up"

所以我在这里问了一个问题,开始实施该解决方案,但它似乎效果不佳 - 我不断收到错误消息“元素的内容必须由格式良好的标记组成”

I am using the NetBeans IDE.

我正在使用 NetBeans IDE。

It seems to center around the < before len

它似乎以 < len 之前为中心

Here's the code that brings up this error:

这是出现此错误的代码:

function formValidation() {

var ids = ["orgname", "cultpicklist", "catpicklist", "servpicklist"],
    formValue = 1;

for (var i = 0, len = ids.length; i < len; i++) {
    if (document.getElementById(ids[i]).value === "") {
       formValue = 0;
       break;
    }

 if (formValue == 1) {
           return true;
      } else if (formValue == 0) {
           alert('Please fill out all required fields');
           return false;
      }
}

回答by Matt Ball

Does this piece of JavaScript happen to live in a <script>tag in an XHTML page? If so, move it to an external JS file, or use a CDATAsection in the script tag.

这段 JavaScript 是否恰好<script>位于 XHTML 页面的标记中?如果是这样,请将其移至外部 JS 文件,或使用CDATA脚本标记中的一个部分