小编scr*_*apy的帖子

如何在更改网页一次后刷新网页?

 

function change(){
    item = document.getElementById("first");
    item.value = "second";
    item.id = "second";
}

ob = document.getElementById("first");
ob.addEventListener("click",change); 

 
Run Code Online (Sandbox Code Playgroud)
 
<input id="first" type="button" value="first"> 
 
Run Code Online (Sandbox Code Playgroud)

单击输入时,它变为:

<input id="second" type="button" value="second"> 
Run Code Online (Sandbox Code Playgroud)

我的要求是编写javascript代码,这样当你点击id为的输入时,second网页就会刷新.也就是说,要更改当前的输入元素:

<input id="second" type="button" value="second"> 
Run Code Online (Sandbox Code Playgroud)

进入上一个:

<input id="first" type="button" value="first"> 
Run Code Online (Sandbox Code Playgroud)

这是我的尝试:

 

function change(){
    item = document.getElementById("first");
    item.value = "second";
    item.id = "second";
}

ob = document.getElementById("first");
ob.addEventListener("click",change); 

function previous(){
    document.execCommand('Refresh') 
}

ob = document.getElementById("second");
ob.addEventListener("click",previous); 
 
Run Code Online (Sandbox Code Playgroud)
   <input id="first" type="button" value="first"> 
Run Code Online (Sandbox Code Playgroud)

error:  Uncaught TypeError: Cannot read property 'addEventListener' of null
at  line27.
Run Code Online (Sandbox Code Playgroud)

html javascript html5 webpage refresh

16
推荐指数
4
解决办法
481
查看次数

何时处理信号以及为什么某些信息会冻结?

  1. 打开一个名为"伏藏"终端,并运行创建的文件callback.sh/bin/bash callback.sh.

    cat  callback.sh
    #!/bin/bash
    myCallback() {
        echo "callback function called at $(date)"
    }
    trap myCallback SIGUSR1
    sleep 20 
    
    Run Code Online (Sandbox Code Playgroud)
  2. 打开一个名为"termB"的新终端并运行:

    pkill -USR1  -f  callback.sh
    
    Run Code Online (Sandbox Code Playgroud)

在termA中20秒后显示以下内容; 它永远不会在termA中显示:

callback function called at Mon Nov 19 08:21:52 HKT 2018
Run Code Online (Sandbox Code Playgroud)

结论证实,当Bash在前台执行外部命令时,它不处理任何接收的信号,直到前台进程终止(参见信号陷阱).

做一点改变callback.sh:

cat  callback.sh
#!/bin/bash
myCallback() {
    echo "callback function called at $(date)"
}
trap myCallback SIGUSR1
while true; do
    read -p  "please input something for foo: " foo
done
Run Code Online (Sandbox Code Playgroud)

添加无限while循环并删除sleep 20.

  1. 打开一个名为"特玛"终端,运行创建的文件callback.sh …

linux bash bash-trap

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

UnicodeDecodeError:'utf-8'编解码器无法解码位置65534-65535中的字节:意外的数据结束

我想用简单的AES加密来加密文件,这是我的python3源代码.

import os, random, struct
from Crypto.Cipher import AES

def encrypt_file(key, in_filename, out_filename=None, chunksize=64*1024):
    if not out_filename:
        out_filename = in_filename + '.enc'
    iv = os.urandom(16)
    encryptor = AES.new(key, AES.MODE_CBC, iv)
    filesize = os.path.getsize(in_filename)
    with open(in_filename, 'rb') as infile:
        with open(out_filename, 'wb') as outfile:
            outfile.write(struct.pack('<Q', filesize))
            outfile.write(iv)
            while True:
                chunk = infile.read(chunksize)
                if len(chunk) == 0:
                    break
                elif len(chunk) % 16 != 0:
                    chunk += ' ' * (16 - len(chunk) % 16)
                outfile.write(encryptor.encrypt(chunk.decode('UTF-8','strict')))
Run Code Online (Sandbox Code Playgroud)

它适用于某些文件,遇到某些文件的错误信息,如下所示:

encrypt_file("qwertyqwertyqwer",'/ tmp/test1',out_filename = None,chunksize = 64*1024) …

python encryption python-3.x

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

同一程序在线程模块中输出不同的输出

start.py代码如下.

import threading
class myThread(threading.Thread):
        def __init__(self, threadID, name):
                threading.Thread.__init__(self)
                self.threadID = threadID
                self.name = name

        def run(self):
                currentThreadname = threading.currentThread()
                print "running in ", currentThreadname

thread = myThread(1,"mythrd")
thread.start()
Run Code Online (Sandbox Code Playgroud)

用python启动它两次.

python start.py
running in  <myThread(mythrd, started 140461133485824)>
python start.py
running in  <myThread(mythrd, started 140122860668672)>
Run Code Online (Sandbox Code Playgroud)

run.py代码如下.

import threading
class myThread(threading.Thread):
        def __init__(self, threadID, name):
                threading.Thread.__init__(self)
                self.threadID = threadID
                self.name = name

        def run(self):
                currentThreadname = threading.currentThread()
                print "running in ", currentThreadname

thread = myThread(1,"mythrd")
thread.run()
Run Code Online (Sandbox Code Playgroud)

run.py只有一行不同于start.py.
现在启动run.py两次.

python  run.py
running …
Run Code Online (Sandbox Code Playgroud)

python multithreading

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

在确认窗口中输入no时不要发送表单数据

类型apple在其名称是输入goods和类型9在其名称输入price,点击submit,现在确认窗口弹出,无论你点击yesno,数据将发送到price.php.
我的期望:
当你点击时yes,数据会发送到price.php,当你点击时no,数据不会发送到price.php,我的js有什么问题?

ob = document.getElementById("submit");
function check(){
    if(document.getElementById("price").value < 10){
        var flag = window.confirm(" are your sure the price is less than 10 ?");
        if(flag){
            return true;
        }else{
            exit;
         }
    }
}
ob.addEventListener("click",check,false); 
 
Run Code Online (Sandbox Code Playgroud)
<form action="price.php" method="post">
<table>
    <tr>
        <td>goods</td>
        <td><input type="text" name="goods"></td>
    </tr>
    <tr>
        <td>price</td>
        <td><input type="text" id="price" name="price"></td>
    </tr>
    <tr><td colspan=2><input type="submit" id="submit"  value="submit"></td></tr> …
Run Code Online (Sandbox Code Playgroud)

javascript confirm

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

如何在.bashrc中创建vim调用函数?

环境:debian9 + vim7.4.

   cat .bashrc
   add(){
        echo $(expr $1 + $2)
    }
Run Code Online (Sandbox Code Playgroud)

现在在vim中编辑一个文件

add 1 5 
Run Code Online (Sandbox Code Playgroud)

在命令模式下运行它:w !bash,发生错误.

bash: line 1: add: command not found    
shell returned 127
Run Code Online (Sandbox Code Playgroud)

1. set shellcmdflag=-ic 在/ etc/vim/vimrc和.bashrc以及.vimrc中添加.
2.reboot
3.vim test.sh
进入命令模式
:verbose set shellcmdflag

  shellcmdflag=-ic
        Last set from ~/.vimrc
Run Code Online (Sandbox Code Playgroud)

4.在test.sh中输入两行

ls
add  5  6

:w !bash     
a1.sh       test.py    
bash: line 2: add: command not found    
shell returned 127    
Run Code Online (Sandbox Code Playgroud)

如何使两条线都执行? 在此输入图像描述
在此输入图像描述

:execute '! source ~/.bashrc; source '.expand('%:p')可以发出两个命令:lsadd运行.

重启后,
1.add函数无法调用 …

vim bash function

11
推荐指数
2
解决办法
1528
查看次数

在多进程模块中运行子进程的顺序

使用for循环启动多进程.

import os
from multiprocessing import Process

def run_proc(name):
    print('child process %s (%s) running ...' %(name,os.getpid()))

if __name__ == '__main__':
    print('parent process %s.' %os.getppid())
    for i in range(5):
        p = Process(target=run_proc,args=(str(i),))
        print('process will start'+str(i))
        p.start()
    p.join()
    print('process is end')
Run Code Online (Sandbox Code Playgroud)

我得到了结果.

parent process 6497.  
process will start  
process will start  
child process 0 (6984) running ...  
process will start  
process will start  
process will start  
child process 2 (6986) running ...  
child process 1 (6985) running ...  
child process 3 (6987) …
Run Code Online (Sandbox Code Playgroud)

python multiprocessing

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

如何在html文件而不是js文件中调用js完成?

我以这种方式为js完成安装了tern_for_vim和YouCompleteMe.

1安装节点

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.2/install.sh | bash
source ~/.nvm/nvm.sh
nvm install node
Run Code Online (Sandbox Code Playgroud)

2安装tern_for_vim

$ cd ~/.vim/bundle
git clone https://github.com/marijnh/tern_for_vim
Run Code Online (Sandbox Code Playgroud)

3安装YouCompleteMe

cd ~/.vim/bundle/YouCompleteMe
$ ./install.sh --clang-completer --tern-completer
Run Code Online (Sandbox Code Playgroud)

4编辑.tern-project

vim  .tern-project  
{
    "libs": [
        "browser",
        "underscore",
        "jquery"
    ],
    "plugins": {
        "node": {}
    }
}
Run Code Online (Sandbox Code Playgroud)

现在来vim test.js.
输入document.test.js文件后弹出js完成.
在此输入图像描述

然后vim test.html 在test.html文件中
输入后弹出没有js完成document..
怎么解决?

javascript vim autocomplete

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

如何在python3中替换没有字符的`c2a0`?

我想转换b'\xc2\xa0\x38'b'x38'python3.

b'\xc2\xa0\x38'.replace(u'\xc2\xa0',"")
b'\xc2\xa0\x38'.replace(u'\xc2a0',"")

TypeError: a bytes-like object is required, not 'str'  
Run Code Online (Sandbox Code Playgroud)

在网页中,c2 a0表示NO-BREAK SPACE,其unicode点为U + 00A0.

Unicode  code point character   UTF-8  (hex.)   name
U+00A0                          c2 a0           NO-BREAK SPACE
Run Code Online (Sandbox Code Playgroud)

注意:c2a0是不可打印的,字符列在这里是空白的.

关于unicode点,字符,utf-8的关系

如何用replace方法转换b'\xc2\xa0\x38'b'\x38'

python string byte replace python-3.x

9
推荐指数
2
解决办法
706
查看次数

为什么不能将信息写入/ tmp目录而不是/ var/www/html?

LAMP安装在我的本地电脑上,因为我知道该字符串xxxx可以/tmp/test用下面的PHP函数写入.

file_put_contents("/tmp/test","test1 test2") 
Run Code Online (Sandbox Code Playgroud)

cat ajax_get.php

<?php
    $str = "test1 test2";
    ini_set('display_errors', 1);
    error_reporting(E_ALL);
    $str = implode(" ",$_GET);
    file_put_contents("/tmp/test",$str);
    print($str);
?>
Run Code Online (Sandbox Code Playgroud)

为什么命令file_put_contents("/tmp/test",$str);ajax_get.php不能工作?

这是没有用的,以取代file_put_contents

$handle=fopen("/tmp/test","w");
fwrite($handle,$str);
fclose($handle);
Run Code Online (Sandbox Code Playgroud)

如果我更改下面的语句,可能是目录权限的问题 ajax_get.php

    file_put_contents("/tmp/test",$str);
Run Code Online (Sandbox Code Playgroud)

    file_put_contents("test",$str);
Run Code Online (Sandbox Code Playgroud)

并运行上一个进程,在其中ajax_get.php创建一个文件/var/www/html/test

cat /var/www/html/test
test1 test2
Run Code Online (Sandbox Code Playgroud)

显示/tmp目录的权限.

ls -al /tmp
total 76
drwxrwxrwt 16 root    root    12288 Dec 10 18:39 .
drwxr-xr-x 23 root    root     4096 Dec  1 08:03 ..
Run Code Online (Sandbox Code Playgroud)

.是当前目录/tmp,其权限是777(rwxrwxrwx),为什么不能通过/tmpPHP …

php file-put-contents

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