Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/449.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 这是一个怎样的问题;Uncaught NotFoundError:尝试在不存在节点的上下文中引用该节点&引用;错误? TLDR:_Javascript_Dom_Textnode - Fatal编程技术网

Javascript 这是一个怎样的问题;Uncaught NotFoundError:尝试在不存在节点的上下文中引用该节点&引用;错误? TLDR:

Javascript 这是一个怎样的问题;Uncaught NotFoundError:尝试在不存在节点的上下文中引用该节点&引用;错误? TLDR:,javascript,dom,textnode,Javascript,Dom,Textnode,见: 举个完整的例子 我不知道为什么取消注释下面注释掉的行会产生错误: “Uncaught NotFoundError:试图在不存在节点的上下文中引用该节点。” (函数(){ //==================================================== //全球的 // // // var div=document.createElement('div'); var bd=document.body; var range=document.createRa

见: 举个完整的例子

我不知道为什么取消注释下面注释掉的行会产生错误: “Uncaught NotFoundError:试图在不存在节点的上下文中引用该节点。”

(函数(){
//====================================================
//全球的
//    
//
//
var div=document.createElement('div');
var bd=document.body;
var range=document.createRange();
div.id='swagyo';
//====================================================
//周围的
//获取一个范围对象并将其包围(使用此)
//
//
//
函数surroundTxt(rangeObj,withThis){
rangeObj.周边内容(带此);
}
//====================================================
//漂亮的文本
//获取一个字符串,在正则表达式处拆分它,预加keepthis,追加addThis
//返回新创建的子字符串的数组。
//
//
函数prettyfyText(str、regExp、addThis、keepthis){
var结果;
如果(str.search(regExp)!=-1){
var splitted=str.split(regExp),
arr=[];
如果(保留此项){
对于(变量i=0;i
本质上,我试图做的是将插入dom中的文本作为文本节点,并用格式化版本替换它

html的一个片段如下所示:

<html>
<body>
    <div id="info">
        <pre>
    /Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -DF_CPU=16000000L -DARDUINO=100 -I/Users/worker_bee/Documents/Arduino/ardu -I/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino -I/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/avr/include/avr -I/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/variants/standard -mmcu=atmega328p applet/ardu.cpp -o applet/ardu.o
        </pre>
    </div>applet/ardu.cpp:2: error: expected unqualified-id before '/' token applet/ardu.cpp: In function 'void setup()': applet/ardu.cpp:14: error: 'outputPin' was not declared in this scope applet/ardu.cpp: In function 'void printStuff()': applet/ardu.cpp:36: error: 'outputPin' was not declared in this scope applet/ardu.cpp:37: error: 'writeStuff' was not declared in this scope applet/ardu.cpp: In function 'void writeStuff()': applet/ardu.cpp:50: error: 'outputPin' was not declared in this scope make: *** [applet/ardu.o] Error 1 
</body>
</html>

/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/avr-g++-c-g-Os-w-fno异常-f函数部分-fdata部分-DF_CPU=16000000L-DARDUINO=100-I/Users/worker_bee/Documents/Arduino/ardu-I/Applications/Arduino.app/Contents/Resources/Java/hardware/Arduino/cores/Arduino-I/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/avr/include/avr-I/Applications/Arduino.app/Contents/Resources/Java/hardware/Arduino/variants/standard-mmcu=atmega328p applet/ardu.cpp-o applet/ardu.o
applet/ardu.cpp:2:错误:在函数“void setup()”中的“/”标记applet/ardu.cpp:之前应为非限定id:applet/ardu.cpp:14:错误:未在此作用域中声明“outputPin”applet/ardu.cpp:在函数“void printsuff()中)“:applet/ardu.cpp:36:错误:“outputPin”未在此作用域中声明applet/ardu.cpp:37:错误:“writeStuff”未在此作用域中声明applet/ardu.cpp:函数“void writeStuff()”:applet/ardu.cpp:50:错误:“outputPin”未在此作用域中声明:**[applet/ardu.o]错误1
为什么要取消注释
<html>
<body>
    <div id="info">
        <pre>
    /Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -DF_CPU=16000000L -DARDUINO=100 -I/Users/worker_bee/Documents/Arduino/ardu -I/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/cores/arduino -I/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/avr/include/avr -I/Applications/Arduino.app/Contents/Resources/Java/hardware/arduino/variants/standard -mmcu=atmega328p applet/ardu.cpp -o applet/ardu.o
        </pre>
    </div>applet/ardu.cpp:2: error: expected unqualified-id before '/' token applet/ardu.cpp: In function 'void setup()': applet/ardu.cpp:14: error: 'outputPin' was not declared in this scope applet/ardu.cpp: In function 'void printStuff()': applet/ardu.cpp:36: error: 'outputPin' was not declared in this scope applet/ardu.cpp:37: error: 'writeStuff' was not declared in this scope applet/ardu.cpp: In function 'void writeStuff()': applet/ardu.cpp:50: error: 'outputPin' was not declared in this scope make: *** [applet/ardu.o] Error 1 
</body>
</html>
newrange = document.createRange()
newrange.setStart(resultArr[i], 0);
newrange.setEnd(resultArr[i], resultArr[i].length);
newrange.surroundContents()