Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/475.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.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 如何从JS创建的子页面替换父页面中的字符串?_Javascript_Replace - Fatal编程技术网

Javascript 如何从JS创建的子页面替换父页面中的字符串?

Javascript 如何从JS创建的子页面替换父页面中的字符串?,javascript,replace,Javascript,Replace,我正在用JS创建一个动态列表 var obj = JSON.parse(Agent212); var i; var serie = "Agent212"; for (i = 0; i < obj.strips.length; i++) { if (obj.strips[i].Collectie == "0") { document.write("<li><a onclick='newPage(" + obj.strips[i].Nummer + "

我正在用JS创建一个动态列表

var obj = JSON.parse(Agent212);
var i;
var serie = "Agent212";
for (i = 0; i < obj.strips.length; i++) {
    if (obj.strips[i].Collectie == "0") {
        document.write("<li><a onclick='newPage(" + obj.strips[i].Nummer + "," + serie + ")' style = 'color:orange'>" + obj.strips[i].Nummer + " - " + obj.strips[i].Titel + "</a></li>");
    }
    else if (obj.strips[i].Collectie == "2") {
        document.write("<li><a onclick='newPage(" + obj.strips[i].Nummer + "," + serie + ")' style = 'color:red'>" + obj.strips[i].Nummer + " - " + obj.strips[i].Titel + "</a></li>");
    }
    else {
        document.write("<li><a class='ToHide' onclick='newPage(" + obj.strips[i].Nummer + "," + serie + ")'><strike>" + obj.strips[i].Nummer + " - " + obj.strips[i].Titel + "</strike></a></li>");
    }
}

但是我不能让它工作,我是不是犯了一个错误?

数组
在代码中发生变化时,你想让DOM更新吗?不,DOM不需要更新。它只是暂时的,这只适用于我在路上的时候。当我在家时,JSON文件将手动更新。
 function newPage(StripNum, SerieNaam) {
     var obj = JSON.parse(SerieNaam);
     var i;
     var x = StripNum;
     for (i = 0; i < obj.strips.length; i++) {
         if (obj.strips[i].Nummer == x) {
             if (obj.strips[i].Collectie == 0) {
                 var myWindow = window.open();
                 myWindow.document.writeln('<html>');
                 myWindow.document.writeln('<head>');
                 myWindow.document.writeln('<meta name="viewport" content="width=device-width, initial-scale=1">');
                 myWindow.document.writeln('<link rel="stylesheet" href="./css/W3CSS.css">');
                 myWindow.document.writeln('<scr' + 'ipt>');
                 myWindow.document.writeln('function windowClose(){');
                 myWindow.document.writeln('window.close();}'); **
                 myWindow.document.writeln('function ToevoegenVerzameling(){'); **
                 myWindow.document.writeln('window.alert("toegevoegd aan verzameling");');
                 myWindow.document.writeln('window.close();');
                 myWindow.document.writeln('}');
                 myWindow.document.writeln('</scr' + 'ipt>');
                 myWindow.document.writeln('</head>');
                 myWindow.document.writeln('<body>');
                 myWindow.document.writeln('<div class="w3-container w3-display-topmiddle">');
                 myWindow.document.writeln('<div class="w3-card-16 w3-round-xlarge" style="width:100%">');
                 myWindow.document.writeln('<a onclick="windowClose();"><center><img src="' + obj.strips[i].Link + obj.strips[i].Nummer + '.jpg"></center></a>');
                 myWindow.document.writeln('<div class="w3-container w3-margin-top">');
                 myWindow.document.writeln('<center><B>Nummer: </B><I>' + obj.strips[i].Nummer + '</I></center>');
                 myWindow.document.writeln('<center><B>Titel: </B><I>' + obj.strips[i].Titel + '</I></center>');
                 myWindow.document.writeln('<center><button onclick="ToevoegenVerzameling()" class="w3-btn w3-light-grey w3-border w3-border-black w3-round-xlarge w3-margin-top w3-margin-bottom" style="width:100%"><h2><b>Toevoegen</b></h2></button></center>');
                 myWindow.document.writeln('</div>');
                 myWindow.document.writeln('</div>');
                 myWindow.document.writeln('</div>');
                 myWindow.document.writeln('</body>');
                 myWindow.document.writeln('</html>');
             }
myWindow.document.writeln('if (window.opener != null && !window.opener.closed){');
myWindow.document.writeln('var str = "<li><a onclick='
    newPage(" + obj.strips[i].Nummer + ", " + serie + ")
    ' style = '
    color: orange '>" + obj.strips[i].Nummer + " - " + obj.strips[i].Titel +"</a></li>";');
myWindow.document.writeln('str.replace("<a onclick='
        newPage(", " < a class = 'ToHide'
            onclick = 'newPage(");'); myWindow.document.writeln('str.replace("style = '
            color: orange '>", "><\strike>");'); myWindow.document.writeln('str.replace("</a>", "</strike></a>");}');