我正在尝试传递一些表单变量来填充网址。只要我只有一个变量,脚本就可以工作。一旦我开始添加多个变量,它就会中断并且按钮不会对onClick执行任何操作。我的剧本出了什么问题?
function ShowOnBaseInvoiceDocument()
{
var onBaseServer = "tudwv-emc01.dong.com";
var appName = "LawsonDev";
var screenID = "AP90";
var accField = "InvoiceNum";
var accField1 = "VendorID";
var company = lawForm.getDataValue("API-COMPANY");
var ProcLvl = lawForm.getDataValue("API-PROC-LEVEL");
var sINVNumber = lawForm.getDataValue("API-INVOICE");
var sVenNumber = lawForm.getDataValue("API-VENDOR");
if (sINVNumber == "")
{
portalWnd.cmnDlg.messageBox("Please inquire on a valid invoice
first.","ok","info",window,false)
return true;
}
var encINVNumber = encodeURIComponent(portalWnd.strTrim(sINVNumber));
var s = "http://"
+ onBaseServer
+ "/OnBaseLinkWebPOC/AccLogin.aspx?DBID="
+ appName
+ "&ScreenID="
+ screenID
+ "&Company="
+ company
+ "&ProcLvl="
+ ProcLvl
+ &
+ accField1
+ "="
+ sVenNumber
+ &
+ accField
+ "="
+ sINVNumber;
//portalWnd.cmnDlg.messageBox(s,"ok","info",window,false)
window.open(s);
return true;
}
答案 0 :(得分:1)
你有很多语法错误。否则,你很好。
请务必更频繁地使用encodeURIComponent()
来获取网址参数。
P.S:window.open()
如果您启用或安装了任何广告拦截器,则无效。暂时禁用它应该有效。
function ShowOnBaseInvoiceDocument() {
var onBaseServer = "tudwv-emc01.dong.com";
var appName = "LawsonDev";
var screenID = "AP90";
var accField = "InvoiceNum";
var accField1 = "VendorID";
var company = "MyCompany";
var ProcLvl = "5";
var sINVNumber = "7567567567";
var sVenNumber = "36456346436";
if (sINVNumber == "") {
portalWnd.cmnDlg.messageBox("Please inquire on a valid invoice first. ", "ok", "info", window, false);
return true;
}
//var encINVNumber = encodeURIComponent(portalWnd.strTrim(sINVNumber));
var s = "http://" +
encodeURIComponent(onBaseServer) +
"/OnBaseLinkWebPOC/AccLogin.aspx?DBID=" +
encodeURIComponent(appName) +
"&ScreenID=" +
encodeURIComponent(screenID) +
"&Company=" +
encodeURIComponent(company) +
"&ProcLvl=" +
encodeURIComponent(ProcLvl) +
"&" +
encodeURIComponent(accField1) +
"=" +
encodeURIComponent(sVenNumber) +
"&" +
encodeURIComponent(accField) +
"=" +
encodeURIComponent(sINVNumber);
//portalWnd.cmnDlg.messageBox(s,"ok","info",window,false)
window.open(s, "My Invoice");
console.log(s);
return true;
}
ShowOnBaseInvoiceDocument();
答案 1 :(得分:1)
我认为最好使用Template Literals / Template Strings让您的生活更轻松。
var s = encodeURIComponent(`http://${onBaseServer}/OnBaseLinkWebPOC/AccLogin.aspx?DBID=${appName}&ScreenID=${screenID}&Company=${company}&ProcLvl=${ProcLvl}&${accField1}=${sVenNumber}&${accField}=${sINVNumber}`);
答案 2 :(得分:0)
function ShowOnBaseInvoiceDocument() {
var onBaseServer = "tudwv-emc01.dong.com";
var appName = "LawsonDev";
var screenID = "AP90";
var accField = "InvoiceNum";
var accField1 = "VendorID";
var company = "MyCompany";
var ProcLvl = "5";
var sINVNumber = "7567567567";
var sVenNumber = "36456346436";
if (sINVNumber == "") {
portalWnd.cmnDlg.messageBox("Please inquire on a valid invoice first. ", "ok", "info", window, false);
return true;
}
//var encINVNumber =
encodeURIComponent(portalWnd.strTrim(sINVNumber));
var s =` http://${onBaseServer}/OnBaseLinkWebPOC/AccLogin.aspx?DBID=${appName}&ScreenID${screenID}&Company=${company}&ProcLvl=${ProcLvl}&${accField1}=${sVenNumber}&${accField}=${sINVNumber};`
//portalWnd.cmnDlg.messageBox(s,"ok","info",window,false)
window.open(s, "My Invoice");
console.log(s);
return true;
}
ShowOnBaseInvoiceDocument();
try using the latest es6 template literals