标签: copying

jQuery在DIV之间复制内容

我正在开发一个我想完全基于Javascript的网站:你加载网站,然后所有页面都被Javascript拉入.

所以我在这里是我拥有的:

    <span id="deathWormButton">Death Worm</span>
    <div id="pageContent">
        <p>Thanks for taking the time to view my portfolio!</p>
        <p>Placeholder content</p>
        <p>Placeholder content</p>
        <p>Placeholder content</p>
        <p>Placeholder content</p>
    </div>
    <div id="DeathWormPage" class="page">
        <p>Thanks for taking the time to view my portfolio!</p>
        <p>Placeholder content</p>
        <p>Placeholder content</p>
        <p>Placeholder content</p>
        <p>Placeholder content</p>
    </div>
Run Code Online (Sandbox Code Playgroud)

这是我的jQuery:

        $(document).ready(function()
        {
            $(".page").hide();
        });
        $("#deathWormButton").click(function()
        {
            $("#pageContent").innerHTML = $("#DeathWormPage").innerHTML;
        });
Run Code Online (Sandbox Code Playgroud)

但它不起作用!(查看此处)

所以,我怎么从复制内容div id="DeathWormPage"div id="pageContent"deathWormButton点击是什么吗?

jquery copying

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

默认构造函数和对象复制

我想知道为什么我需要在这种情况下声明一个默认构造函数.首先,如果我把它遗漏,编译器是否会自动执行此操作?无论如何,我仍然不明白为什么它是必要的.此外,即使我省略'obj_B = origin.obj_B;',我也会收到错误.

class B
{
public:
    bool theArray[5] ;

    B(bool x) {theArray[1] = x;};
    //B(){};    
};

class A
{
public:
    B obj_B;

    A() : obj_B(1) {};
    A(A const &origin) {obj_B = origin.obj_B;}; //error:no matching function for call 
                                                      //to B::B()
}; 

int main () 
{
    std::vector <A> someAs;
    for(int q=0;q<10;q++)
        someAs.push_back(A());

    for(int q=0;q<10;q++)
        std::cout << someAs[q].obj_B.theArray[1] << std::endl;
}
Run Code Online (Sandbox Code Playgroud)

c++ constructor copying assignment-operator

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

复制文件时,在Python中使用os.stat的修改时间会降低

我遇到的问题是在路径上使用os.stat的一部分(例如,以C:\ myfile1.txt为例).当我在这个文件上运行os.stat并在结果列表中取第9个元素时,我得到了一些数字形式的修改时间(例如1348167977).

注意:我不确定如何计算这些数字.

当我创建C:\ myfile1.txt时,它有一些数字,如上例所示.如果我创建另一个文件C:\ myfile2.txt,它会得到一个代表修改时间的新数字,该数字高于C:\ myfile1.txt(这就像我期望的那样).我还有一个最后创建的第三个文件C:\ myfile3.txt.

如果我复制C:\ myfile2.txt并用生成的复制文件覆盖C:\ myfile3.txt,则会出现问题,新的C:\ myfile3.txt上的os.stat显示的修改时间小于C:\ myfile1.txt.为什么会这样?C:\ myfile3.txt的修改时间应该是最高或者至少等于C:\ myfile2.txt.

谢谢你的回答,我希望我能够解释得很清楚.

编辑:

这里有一些示例代码来测试我描述的内容.有时,如果你在不同的时间重新运行数字,它们的工作原理会有所不同.我想我只是不完全理解我输出的MTIME.

import os
import shutil
import time

myfile1 = open("C:\\myfile1.txt", 'wt')
myfile1.close()
time.sleep(10)
myfile2 = open("C:\\myfile2.txt", 'wt')
myfile2.close()
time.sleep(10)
myfile2 = open("C:\\myfile3.txt", 'wt')
myfile2.close()

shutil.copyfile("C:\\myfile2.txt", "C:\\myfile3.txt")

modified_time_first = (os.stat("C:\\myfile1.txt")[9])
modified_time_second = (os.stat("C:\\myfile2.txt")[9])
modified_time_third = (os.stat("C:\\myfile3.txt")[9])

print "The first files modified time is: "
print modified_time_first
print ""

print "The second files modified time is: " 
print modified_time_second
print ""

print "The third files …
Run Code Online (Sandbox Code Playgroud)

python file copying stat

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

复制数组导致0?

我正在学习C,我的一个函数(这里没有显示)依赖于两个数组是相同的.我有一个数组,我正在尝试生成一个副本,但会发生的是,两个数组在复制后都变成了0.我不知道这是怎么发生的.任何人都可以帮助解释为什么会发生这种情况并提供一个如何做到正确的解决方案?

#include <stdio.h>

int main(){

    int array[5]={3,2,7,4,8};
    int other_array[5]={0,0,0,0,0};

    for (int i=0; i<5; i++) array[i]=other_array[i];    //Copies array into other_array

    printf("array is:\n");
    for (int j=0; j<5; j++) printf("%d", array[j]);
    printf("\nother_array is:\n");
    for (int i=0; i<5; i++) printf("%d", other_array[i]);
    printf("\n");

    return 0;
}

/*
When run this yields
**********************
array is:
00000
other_array is:
00000
*/
Run Code Online (Sandbox Code Playgroud)

c arrays copying

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

设置A = B是否与B混乱?(所有向量)C++

我正在制作一个匹配两个字符串向量的函数.作为该功能的一部分,我需要制作载体的副本.我想在函数的开头做这个,但不知何故,如果我这样做,它会使我的函数崩溃.这就是我想要设置的功能

vector<string> match(vector<string> & u,vector<string> & v){

// I would like to define these first, but that crashes my function
    vector<string> u1=u;
    vector<string> v1=v;
    u1.erase(u1.begin());
    v1.erase(v1.begin());
// I would like to define these first, but that crashes my function

    if(u.size()==0){
        return u;
    }
    if(v.size()==0){
        return v;
    }

    if(u.at(0)==v.at(0)){
        vector<string>result=match(u1,v1);
        result.insert(result.begin(),u[0]);
        return result;
    }

    if(match(u,v1)>=match(u1,v)){
        vector<string>result= match(u,v1);
        return result;
    }

    else{
        return match(u1,v);
    }
}
Run Code Online (Sandbox Code Playgroud)

然而,一个简单的开关使功能工作,我不明白为什么

vector<string> match(vector<string> & u,vector<string> & v){

//Putting these if statements first makes the function work …
Run Code Online (Sandbox Code Playgroud)

c++ vector copying

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

复制一个dict,留下一个(key,val)对

在Python 3中,如何复制字典而只留下一个元素?两个dicts之间的数据共享对我来说很好.目前我有这个代码:

def copy_leaving_out(dictionary, key):
    return {k: v for k, v in dictionary if k != key}
Run Code Online (Sandbox Code Playgroud)

有没有更好的方法来实现这一目标?

编辑:我忘了使用dictionary.items()而不是dictionary,请考虑以下代码而不是前一个代码:

def copy_leaving_out(dictionary, key):
    return {k: v for k, v in dictionary.items() if k != key}
Run Code Online (Sandbox Code Playgroud)

python dictionary copying python-3.x

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

C++ - 从const char*复制到string

有没有办法从字符串复制const char*string在C++?我正在尝试做这样的事情:

#include <iostream>
#include <string.h>

using namespace std;

int main(){

    string s1;
    const char* pStr = "Sample Text";

    for(int i = 0; i < strlen(pStr); i++)
        s1[i] = pStr[i];

    cout<<s1<<endl;

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

在我的情况下,s1原来是空的.

c++ string copying

-2
推荐指数
1
解决办法
7404
查看次数