gpt4 book ai didi

Javascript 函数未正确调用

转载 作者:行者123 更新时间:2023-12-03 08:25:45 25 4
gpt4 key购买 nike

我有一个 JavaScript 函数

function createHyperLinkDraft(){ 
var xWin = window.opener;
var hyperLink = document.addHyperLinkForm.hyperLinkNameDraft.value;

if(hyperLink){

var urlList = "openDraftFilesAction.action?draftID="+ document.addHyperLinkForm.DraftNo.value ;
hyperLinkName = "&nbsp;<a style='text-decoration:underline;cursor:pointer' onclick=javascript:window.open('"+urlList+"','subWindow','HEIGHT=600,WIDTH=600,screenX=100,left=100,screenY=100,top=100')>"+ hyperLink +"</a>&nbsp;";

xWin.Xinha._currentlyActiveEditor.insertHTML(hyperLinkName);

document.addHyperLinkForm.reset();
window.close();
}
}

这将存储在注释编辑器中。但是当我在我的操作类中看到它被存储为

<p>l&nbsp;<a onclick="javascript:window.open('openDraftFilesAction.action? draftID=9/1021/2015-FT-COORD-new" 3?,?subwindow?,?height="600,WIDTH=600,screenX=100,left=100,screenY=100,top=100')" style="cursor: pointer; text-decoration: underline">link</a>&nbsp;</p>

其中实际草稿 ID 为 9/1021/2015-FT-COORD-new file 12oct/3。

因此,该草案尚未开放。我不明白为什么会发生这种情况。

最佳答案

您需要使用encodeURIComponent()对其进行编码

来自 MDN:

The encodeURIComponent() method encodes a Uniform Resource Identifier (URI) component by replacing each instance of certain characters by one, two, three, or four escape sequences representing the UTF-8 encoding of the character (will only be four escape sequences for characters composed of two "surrogate" characters).

function createHyperLinkDraft() { 
var xWin = window.opener;
var hyperLink = document.addHyperLinkForm.hyperLinkNameDraft.value;

if (hyperLink) {
var urlID = document.addHyperLinkForm.DraftNo.value;
urlID = encodeURIComponent(urlID);
var urlList = "openDraftFilesAction.action?draftID="+ urlID;
hyperLinkName = "&nbsp;<a style='text-decoration:underline;cursor:pointer' onclick=javascript:window.open('"+urlList+"','subWindow','HEIGHT=600,WIDTH=600,screenX=100,left=100,screenY=100,top=100')>"+ hyperLink +"</a>&nbsp;";

xWin.Xinha._currentlyActiveEditor.insertHTML(hyperLinkName);

document.addHyperLinkForm.reset();
window.close();
}
}

关于Javascript 函数未正确调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33560621/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com