| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 
 | <html>
<head>
<title>Code de démonstration - Explorer un tableau HTML avec des interfaces DOM et JavaScript</title>
<script>
// Example ObjetSmartLink en json
var SmartlinkJson = {"id_source":"7315f47dba65515fca60c851d7065bc6","url_source":"http:\/\/news.yahoo.com\/s\/afp\/20060822\/od_afp\/chinacateringcultureoffbeat_060822074830","title_source":"Jail-theme teahouse becomes prisoner of own success in China - Yahoo! News","smartlinks_infos":[{"id_dest":"75effc69e8c68b389c65c67119463312","score":"126","deleted":"0","date":"1164279208","zone_cible":"151","manually_added":"0","url_dest":"http:\/\/news.yahoo.com\/s\/afp\/20060825\/od_afp\/malaysiahealthtoilets_060825160532","title_dest":"Malaysia calls for \"toilet revolution\" - Yahoo! News"}]};
//var SmartlinkJson = <?= $jsonstring ?>
//fonction de construction de SmartLinks
 
var SmartLink = eval(SmartlinkJson);
alert(SmartLink.id_source);
 
 
//fonction d'affichage de SmartLinks
function DisplaySmartLinks (SmartLink) {
 
   //récupere une référence vers l'élément SmartLinks
   var zone_affichage = document.getElementById("SmartLink")
 
	//var TableCible=new Array('Titre_Cible"', 'Date_cible');
	var Props=new Array('id_source', 'url_source', 'title_source', 'smartlinks_info');
        // récupère une référence vers l'élément body
       // var mybody = document.getElementsByTagName("body")[0];
 
        // création des éléments <table> et <tbody>
        smartlinksTable = document.createElement("table");
        smartlinksTbody = document.createElement("tbody");
//for (p=0;p<Props.length;p++){
        // création des cellules
        for(var j = 0; j < 2; j++) {
            // création d'un élément <tr>
            smartlinksLine = document.createElement("tr");
 
            // création du premier élément <td> de la ligne SmartLinks
             smartlinksCell1 = document.createElement("td");
                for (k=0; k<2; k++) {
 
                smartlinksCell1.innerHTML += 'cellule source<br />';
                //smartlinksCell1.innerHTML +=SmartLink[Props[p]]
                }
                // ajoute la premiere cellule <td> à la ligne <tr>
                smartlinksLine.appendChild(smartlinksCell1);
 
                // création du second élément <td> de la ligne smartlinks
             smartlinksCell2 = document.createElement("td");
                for (l=0; l<6; l++) {
                smartlinksCell2.innerHTML += 'liens cibles<br />';
                }
                // ajoute la seconde cellule <td> à la ligne <tr>
                smartlinksLine.appendChild(smartlinksCell2);
 
            // ajoute la ligne <tr> à l'élément <tbody>
            smartlinksTbody.appendChild(smartlinksLine);
       // }
}
        // ajoute <tbody> à l'élément <table>
        smartlinksTable.appendChild(smartlinksTbody);
        // ajoute <table> à l'élément <body>
        zone_affichage.appendChild(smartlinksTable);
        // définit l'attribut border de mytable à 2
        smartlinksTable.setAttribute("border", "1");
    }
</script>
</head>
<body onload="DisplaySmartLinks()">
<div id="Smartlink">
le test d'affichage
</div>
</body>
</html> | 
Partager