0

私は他の開発者が開始したプロジェクトに取り組んでおり、プロジェクトを完了しながらコードを理解しようとしています。現在、私が持っているのは、リンクと URL テキスト (かなり簡単な説明) を含む json です。必要なのは、ボタンをクリックすることです。各リンクを正しいテキストで表示し、クリック可能なリンクにします。これを行う必要がある方法は、私が 100% の知識を持っていないノードを使用することです。これについてさらに説明する必要がある場合は、私が現在取り組んでいるものの例を提供したこともお知らせください. ありがとう

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
    <title>JavaScript And JSON</title>
</head>
<body bgcolor='#CED3F3'>

    <button onclick="appendUrl()">Append</button><br>

<br><script id = "i">
    function category()
    //adding function with button click removes html page styling?
       {
        var category = {
                "content": [
                {
                "links": "basic information",
                "urlText": "Basis Information System",
                "urlDesc": "portal for technology development, people search, a keyword search ."
                },
                {
                "links": "http://site.com",
                "urlText": "Net",
                "urlDesc": "the entry page example"
                },
                {
                "links": "http://newsgroups.com",
                "urlText": "Newsgroups",
                "urlDesc": "information internal newsgroups, usage, tools, statistics, netiquette"
                },
                {
                "links": "http://site2.com",
                "urlText": "Another site",
                "urlDesc": "community for transfer of knowledge and technical information"
                },
                {
                "links": "http://news.com",
                "urlText": " some news",
                "urlDesc": "place with news"
                }
            ]
        }

</script>
<script>
    function appendUrl()
        {
        //there needs to be a loop here?
            var link = "needs to loop through links?"
            var node=document.createElement("LI");
            var nodeA=document.createElement("A");
            var textnode=document.createTextNode();
                node.appendChild(nodeA);
                nodeA.appendChild(textnode);
                nodeA.href=(link);
                nodeA.target="_blank";
                document.getElementById("i").appendChild(node);                     
        }   
</script>
</body>
</html>
4

2 に答える 2