开发者

Problems with validating a document when trying to create a nested list using javascript

开发者 https://www.devze.com 2023-03-19 09:16 出处:网络
Here is my whole document.I\'m having problems with the part in the head that starts with var tabNom1

Here is my whole document. I'm having problems with the part in the head that starts with var tabNom1

and in the body after "Partie 2: Affichage du contenu HTML à partir de JavaScript" and before "Partie 3: Affichage et animation des images"

I am getting these errors:

Line 58, Column 28: document type does not allow element "ul" here
        document.write("<ul>"); Line 58, Column 29: character data is not allowed here
        document.write("<ul>"); Line 60, Column 29: character data is not allowed here
        document.write("<ul>开发者_开发技巧;"); Line 62, Column 53: character data is not allowed here
        {document.write("<li>" + tabNom1[x] + "</li>");}

In this document:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>


<meta content="fr-ca" http-equiv="Content-Language"/>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type"/>
<meta http-equiv="content-style-type" content="text/css"/>

<title>TP3</title>

<script type="text/javascript">
                function addNumbers()
                {
                        var val1 = parseInt(document.getElementById("Notetp1").value);
                        var val2 = parseInt(document.getElementById("Notetp2").value);
                        var val3 = parseInt(document.getElementById("Notetp3").value);
                        var val4 = parseInt(document.getElementById("Noteexamenintra").value);
                        var val5 = parseInt(document.getElementById("Noteexamenfinal").value);

                        var ansD = document.getElementById("Note finale");
                        ansD.value = val1 + val2 + val3 +val4 + val5;
                }


var tabNom1 = {"Nom": "Smith", "Prenom": "John", "CodePermanent": "SMIT23325202", "Login": "Smith" }; 
 </script>

<style type="text/css">

  body {font-family:"Times New Roman", Times, serif;}  
  h2 {font-weight:bold;}

 </style>

</head>

 <body>


<h2>Partie 1: Formulaire du calcul de la note</h2>


        Note tp1 : <input id="Notetp1" name="Note tp1" value="" type="text"/>
        Note tp2 : <input id="Notetp2" name="Note tp2" value="" type="text"/>
        Note tp3 : <input id="Notetp3" name="Note tp3" value="" type="text"/>
        Note examen intra : <input id="Noteexamenintra" name="Note examen intra" value=""   type="text"/>
        Note examen final : <input id="Noteexamenfinal" name="Note examen final" value="" type="text"/>
        <input name="Sumbit" value="Afficher la note finale" onclick="javascript:addNumbers()" type="button"/>
        Note final : <input id="Notefinal" name="Note final" value="" type="text"/>


<h2>Partie 2: Affichage du contenu HTML à partir de JavaScript</h2>


        <script type="text/javascript">


        document.write("<ul>");
        document.write("<li>" + "Equipier numéro 1:");
        document.write("<ul>");
        for (x in tabNom1) 
        {document.write("<li>" + tabNom1[x] + "</li>");}
        document.write("</ul></li></ul>");

</script>

<h2>Partie 3: Affichage et animation des images</h2>

</body></html>


As noted to the answer to the first iteration of this question, update your body script as follows:

<script type="text/javascript">
//<![CDATA[
    document.write("<ul>");
    document.write("<li>" + "Equipier numéro 1:");
    document.write("<ul>");
    for (x in tabNom1) 
    {document.write("<li>" + tabNom1[x] + "<\/li>");}
    document.write("<\/ul><\/li><\/ul>");
//]]>
</script>

That's adding CDATA and escaping the / in your closing elements.

See http://www.w3resource.com/javascript/document-alert-confirm/writing-text.php for examples.

0

精彩评论

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