小编ord*_*anj的帖子

如何在页面加载时将HTML插入div?

我花了很长时间在SO上寻找我的问题的一个很好的答案,但是没有任何事情达到目标……所以去了。我正在使用jquery,javascript,html和jquery-mobile来创建各种电子书。每个目录页面上都有一个可从幻灯片面板访问的目录。目录是一组嵌套的li和ul元素,包含在每个页面上重复使用的html。如果您熟悉jquery mobile,我会将此列表层次结构插入<div data-role=panel>部分,以在幻灯片面板中创建可折叠列表元素。现在,我这样做的方法是在每个页面上放置完全相同的目录代码表。显然,这是一种糟糕的方法。我需要找到一种方法将此目录代码嵌入到需要它的每个页面中,以便在进行更改时只更新一次目录,而不是在每个页面上对其进行更新。现在我正在这样做...

<div data-role="panel" id="TOC" data-icon="grid" data-display="overlay">
                <script>
                    $('#TOC').load('example.TOC.html')
                </script> 

            </div> <!--This is the end of the slide panel section-->
Run Code Online (Sandbox Code Playgroud)

html正在加载,但无法访问jquery mobile,jquery或我创建的任何外部javascript文件。我想了解原因。我正在加载中的所有资源<head>,目录正在中加载<body>。因此,您认为这可以工作...但是,要使滑动面板正常工作,唯一的方法是将头部复制到目录文件中。抱歉,冗长的解释...但是这里有一些代码需要澄清。

<!doctype html> <html>
<head>
    <title class="link-1-1-1-2" <!--id="link-1-1-1-2"--> >Part 2</title> 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
        <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css"></link>

        <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
        <script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>
        <script src="../Support/js/jStorage.js"></script>
        <script src="../Support/js/bookmark2.js"></script>
        <script src="../Support/js/linknavigation.js"></script>


</head>
<body>
    <div data-role="page">



        <!--begin header-->
        <div data-role="header" data-position="fixed">
            <a data-icon="grid" href="#TOC">Table of Contents</a>
            <h1>Part 2</h1>
            <button data-icon="check" id="bookmarkPage"> Bookmark </button>
        </div><!-- /header -->

        <!--begin …
Run Code Online (Sandbox Code Playgroud)

html javascript jquery jquery-mobile

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

在读取多个配置文件时,ConfigParser会覆盖以前的文件,为什么?

所以我想首先说我一直在寻找SO的答案,并且找不到任何有用的东西.我也查看了Python的文档,但未能找到有用的东西.我的上一个问题有点懒,收到负面反馈,所以我尽我所能在这里提出一个简单明了的问题.一如既往,提前感谢您的帮助!

那么,有人可以解释我在Python的ConfigParser中遇到的奇怪行为.我有两个不同的配置文件,每个都有一个Section 1.这两个文件具有不同数量的选项,但覆盖的选项数量较少.这是代码和输出:

第一个配置文件:test1.ini

[Section 1]
Option 1 : One
Option 2 : Two
Option 3 : None
Option 4 : Four
Run Code Online (Sandbox Code Playgroud)

第二个配置文件:test2.ini

[Section 1]
Option 1 : One
Option 2 : None
Option 3 : Three
Run Code Online (Sandbox Code Playgroud)

读取配置文件的驱动程序

from ConfigParser import SafeConfigParser

parser = SafeConfigParser()

def ParseThis(file, section):
    parser.read(file)

    for option in parser.options(section):
        print "\t" + option
        try:
            if parser.get(section, option) != 'None':
                print option + ": " + parser.get(section, option)
            else:
                print option + ": Option doesn't …
Run Code Online (Sandbox Code Playgroud)

python configparser

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

在TreeSet中查找包含前缀的条目

我在Java中有一个包含字符串(特别是单词)的TreeSet.我需要写一个方法......

public boolean isValidPrefix(String prefix)

...接受前缀作为参数并检查TreeSet以查看其包含的任何单词是否以前缀开头.

例如,给定前缀"CA"和包含{"DOG","CAT","COW"}的TreeSet ,我的方法需要确定存在以前缀开头的单词"CAT".

PS我将遍历TreeSet,但时间复杂度是一个明显的约束,因为在许多情况下TreeList将达到200,000个单词.

java string treeset

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

如果没有错误,回调是否应该传递null或undefined?

我希望这是一个简单的问题.回调的最佳做法是哪种?

选项1:

function get (id, callback) {
    var topic = find(id);
    var err = new Error('Sorry, ' + id + ' is not a valid id.');
    err.status = 404;
    return (topic) ? callback(null, topic) : callback(err);
}
Run Code Online (Sandbox Code Playgroud)

选项2:

function get (id, callback) {
    var topic = find(id);
    var err = new Error('Sorry, ' + id + ' is not a valid id.');
    err.status = 404;
    return (topic) ? callback(undefined, topic) : callback(err);
}
Run Code Online (Sandbox Code Playgroud)

旁注,find()返回undefined,而不是null.

提前致谢.

javascript node.js

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