开发者

Odd HTML validation error

开发者 https://www.devze.com 2023-02-10 01:17 出处:网络
I\'m getting an odd HTML validation error from this piece of JavaScript any help appreciated, I think it may be causing a bug in the slider function that I\'m working with...

I'm getting an odd HTML validation error from this piece of JavaScript any help appreciated, I think it may be causing a bug in the slider function that I'm working with...

<script type="text/javascript" charset="utf-8">
        sfHover = function() {
            var sfEls = document.getElementById("nav2").getElementsByTagName("LI");
            for (var i=0; i<sfEls.length; i++) {
                sfEls[i].onmouseover=function() {
                    this.className+=" sfhover";
                }
                sfEls[i].onmouseout=function() {
                    this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
                }
            }
        }
        if (window.attachEvent) window.attachEvent("onload", sfHover);
    </script>

The errors are

Error: character ";" not allowed in attribute 开发者_Python百科specification list

and

Error: element "sfEls.length" undefined

from the line

for (var i=0; i

and

Error: end tag for "sfEls.length" omitted, but OMITTAG NO was specified

from the closing script tag


Your Javascript contains special characters for XML (< and &).
Therefore, it's invalid markup.

You need to wrap it in a CDATA section, which will prevent the XML parser from parsing its contents:

<script type="text/javascript">
    //<![CDATA[
    ...
    //]]>
</script>

The comments are necessary to prevent the CDATA section from causing Javascript syntax errors in browsers that don't recognize it

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号