小编lim*_*ker的帖子

ReferenceError:未定义文档(在纯JavaScript中)

尝试时,我得到一个"ReferenceError:文档未定义"

var body = document.getElementsByTagName("body")[0];
Run Code Online (Sandbox Code Playgroud)

我之前在其他代码中看过这个,并没有造成任何麻烦.为什么现在呢?随之而来的HTML页面只是体内的一个div.

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
    <link rel="stylesheet" type="text/css" href="css/quiz.css" />
    <script type="text/javascript" src="js/quiz.js"></script>
</head>
<body>

    <div id="divid">Next</div>

</body>
</html>
Run Code Online (Sandbox Code Playgroud)

代码如下:

(function(){
        var body = document.getElementsByTagName("body")[0];

        function Question(question, choices, correctAns) {
            this.question = question;
            this.choices = choices;
            this.correctAns = correctAns;
        }

        Question.prototype.checkAns = function(givenAns){
            if (this.correctAns === givenAns) {
                console.log("OK");
            }
        };

        function Quiz() {
            this.questions = [];
        }

        Quiz.prototype.showAllQuestions = function(){
            this.questions.forEach(function(questions){
                console.log(questions.question);
            });
        };

        Quiz.prototype.showQuiz = function(){
            this.questions.forEach(function(questions){

                for (var …
Run Code Online (Sandbox Code Playgroud)

javascript

19
推荐指数
4
解决办法
15万
查看次数

如何使用Python获取树的叶节点?

嗨,我是OOP的新手,所以在阅读本文时请记住这一点.

我有一个简单的Python树实现(见下面的代码).

class TreeNode(object):
    def __init__(self, data):
        self.data = data
        self.children = []

    def add_child(self, obj):
        self.children.append(obj)

class Tree:
    def __init__(self):
        self.root = TreeNode('ROOT')

    def preorder_trav(self, node):
        if node is not None:
            print node.data
            if len(node.children) == 0:
                print "("+ node.data + ")"
                for n in node.children:
                    self.preorder_trav(n)

if __name__ == '__main__':
    tr = Tree()
    n1 = tr.root
    n2 = TreeNode("B")
    n3 = TreeNode("C")
    n4 = TreeNode("D")
    n5 = TreeNode("E")
    n6 = TreeNode("F")

    n1.add_child(n2)
    n1.add_child(n3)
    n2.add_child(n4)
    n2.add_child(n5)
    n3.add_child(n6)

    tr.preorder_trav(n1)
Run Code Online (Sandbox Code Playgroud)

我现在需要的是实现一个获取Leaf …

python oop tree

4
推荐指数
1
解决办法
2万
查看次数

为了了解 QEMU 如何模拟支持的网络设备,我需要阅读/分析什么?

我想分析一下QEMU如何模拟支持的网络设备读取源代码。另外我想与我分享一下您对理解 QEMU 源代码需要什么背景的看法。请向我推荐一些围绕主题的好书或在线资源,为了实现这一目标,人们必须学习这些主题(我想需要设备驱动程序、处理器规范等?)。另外,如果你能告诉我用 C 语言应该达到的编程水平(因为源代码是用 C 语言编写的),那就太好了。

我已经浏览过 QEMU 的网站,其中提供的内容主要涉及如何使用 QEMU 和配置它。

qemu device processors device-emulation

1
推荐指数
1
解决办法
1638
查看次数

标签 统计

device ×1

device-emulation ×1

javascript ×1

oop ×1

processors ×1

python ×1

qemu ×1

tree ×1