2017-11-17 191 views
0

我很高兴地看到,我能够解决my previous problem(有一些急需帮助)。但不久后,我已经跑了新的代码:运行在一个控制台JavaScript代码VS作为bookmarkl给出不同的结果

javascript:var tt=document.createElement('div'); 
 
tt.setAttribute('id', 'CMenu'); 
 
var g=document.getElementById('adCost'); 
 
var RAW='<button id ="save1Button" onclick=\"save1()\">SAVE SLOT 1</button>' + 
 
'<button id ="load1Button" onclick="load1()">LOAD SLOT 1</button>' + 
 
'<button id ="save2Button" onclick="save2()">SAVE SLOT 2</button>' + 
 
'<button id ="load2Button" onclick="load2()">LOAD SLOT 2</button>' + 
 
'<button id ="resetButton" onclick="reset()">RESET ALL PROGRESS</button>' + 
 
'<button id ="freeClipsButton" onclick="cheatClips()">Free Clips</button>' + 
 
'<button id ="freeMoneyButton" onclick="cheatMoney()">Free Money</button>' + 
 
'<button id ="freeTrustButton" onclick="cheatTrust()">Free Trust</button>' + 
 
'<button id ="freeOpsButton" onclick="cheatOps()">Free Ops</button>' + 
 
'<button id ="freeCreatButton" onclick="cheatCreat()">Free Creativity</button>' + 
 
'<button id ="freeYomiButton" onclick="cheatYomi()">Free Yomi</button>' + 
 
'<button id ="resetPrestige" onclick="resetPrestige()">Reset Prestige</button>' + 
 
'<button id ="destroyAllHumansButton" onclick="cheatHypno()">Destroy all Humans</button>' + 
 
'<button id ="freePrestigeU" onclick="cheatPrestigeU()">Free Prestige U</button>' + 
 
'<button id ="freePrestigeS" onclick="cheatPrestigeS()">Free Prestige S</button>' + 
 
'<button id ="debugBattleNumbers" onclick="setB()">Set Battle Number 1 to 7</button>' + 
 
'<button id ="availMatterZero" onclick="zeroMatter()">Set Avail Matter to 0</button>'; 
 
g.appendChild(tt); 
 
document.getElementById('CMenu').innerHTML= RAW

为书签,而不是在控制台(无javascript:当然),它给了不同的结果。在逐行测试时,控制台按预期运行它,并且一次完成。然而书签用按钮替换了页面上的所有内容!

+0

为什么你不只是做'tt.innerHTML = RAW'? – Barmar

+0

当我编写原始代码时,我很累。我只是忘了粘贴最新的一个。尽管如此,他们的工作原理是一样 – LCB

+0

这很奇怪。我仍然可以在DevTools的Elements面板中看到页面的其余部分,但它们不会出现在浏览器选项卡中。将鼠标悬停在检查器中的元素上不会突出显示浏览器选项卡中的任何内容。 – Barmar

回答

0

false添加到小书签的末尾。显然浏览器将点击书签作为导航,所以当它返回时它只显示新的页面。但是,如果内联Javascript返回false,则会禁用单击链接的默认操作。

<a href="javascript:var tt=document.createElement('div'); 
 
tt.setAttribute('id', 'CMenu'); 
 
var g=document.getElementById('adCost'); 
 
var RAW='<button id =&quot;save1Button&quot; onclick=&quot;save1()&quot;>SAVE SLOT 1</button>' + 
 
'<button id =&quot;load1Button&quot; onclick=&quot;load1()&quot;>LOAD SLOT 1</button>' + 
 
'<button id =&quot;save2Button&quot; onclick=&quot;save2()&quot;>SAVE SLOT 2</button>' + 
 
'<button id =&quot;load2Button&quot; onclick=&quot;load2()&quot;>LOAD SLOT 2</button>' + 
 
'<button id =&quot;resetButton&quot; onclick=&quot;reset()&quot;>RESET ALL PROGRESS</button>' + 
 
'<button id =&quot;freeClipsButton&quot; onclick=&quot;cheatClips()&quot;>Free Clips</button>' + 
 
'<button id =&quot;freeMoneyButton&quot; onclick=&quot;cheatMoney()&quot;>Free Money</button>' + 
 
'<button id =&quot;freeTrustButton&quot; onclick=&quot;cheatTrust()&quot;>Free Trust</button>' + 
 
'<button id =&quot;freeOpsButton&quot; onclick=&quot;cheatOps()&quot;>Free Ops</button>' + 
 
'<button id =&quot;freeCreatButton&quot; onclick=&quot;cheatCreat()&quot;>Free Creativity</button>' + 
 
'<button id =&quot;freeYomiButton&quot; onclick=&quot;cheatYomi()&quot;>Free Yomi</button>' + 
 
'<button id =&quot;resetPrestige&quot; onclick=&quot;resetPrestige()&quot;>Reset Prestige</button>' + 
 
'<button id =&quot;destroyAllHumansButton&quot; onclick=&quot;cheatHypno()&quot;>Destroy all Humans</button>' + 
 
'<button id =&quot;freePrestigeU&quot; onclick=&quot;cheatPrestigeU()&quot;>Free Prestige U</button>' + 
 
'<button id =&quot;freePrestigeS&quot; onclick=&quot;cheatPrestigeS()&quot;>Free Prestige S</button>' + 
 
'<button id =&quot;debugBattleNumbers&quot; onclick=&quot;setB()&quot;>Set Battle Number 1 to 7</button>' + 
 
'<button id =&quot;availMatterZero&quot; onclick=&quot;zeroMatter()&quot;>Set Avail Matter to 0</button>'; 
 
g.appendChild(tt); 
 
document.getElementById('CMenu').innerHTML= RAW; 
 
false;">Click</a> 
 
<div>This is some text at the beginning.</div> 
 
<div id="adCost"></div> 
 
<div>This is text at the end</div>

+0

解决!非常感谢! – LCB

相关问题