- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的 JS 代码构造得非常糟糕,我需要使用 do-while 或使用像 for (i=0;i<10;i++)
这样的增量来缩短它.该脚本运行良好,但效果不佳。
我正在尝试将 VMware 中的文件夹树结构导出到具有两个属性的对象数组中 - “文件夹名称”和“文件夹路径”。我使用 vCenter 插件来查询数据。这是库存图片 -
这是代码 -
function getFolderPath(dc)
{
var row = [];
var VcFolders = VcPlugin.getAllVmFolders()
for each(VcFolder in VcFolders)
{
if (VcFolder.sdkConnection.name.match(dc.sdkConnection.name))
{
if (VcFolder.name == "vm")
{
if (VcFolder.parent instanceof VcDatacenter)
{
if (VcFolder.parent.name == dc.name)
{
var parentFolder = VcFolder;
for each (child in parentFolder.childEntity)
{
if (child.vimType == "Folder")
{
var current = child.parent
var path = child.name
do {
var parent = current
if (parent.name != "vm")
{
path = parent.name + "\\" + path
}
current = current.parent
} while (current.parent != null)
row.push({
Name: child.name,
Path: path
})
for each (child1 in child.childEntity)
{
if (child1.vimType == "Folder")
{
var current = child1.parent
var path1 = child1.name
do {
var parent = current
if (parent.name != "vm")
{
path1 = parent.name + "\\" + path1
}
current = current.parent
} while (current.parent != null)
row.push({
Name: child1.name,
Path: path1
})
for each (child2 in child1.childEntity)
{
if (child2.vimType == "Folder")
{
var current = child2.parent
var path2 = child2.name
do {
var parent = current
if (parent.name != "vm")
{
path2 = parent.name + "\\" + path2
}
current = current.parent
} while (current.parent != null)
row.push({
Name: child2.name,
Path: path2
})
for each (child3 in child2.childEntity)
{
if (child3.vimType == "Folder")
{
var current = child3.parent
var path3 = child3.name
do {
var parent = current
if (parent.name != "vm")
{
path3 = parent.name + "\\" + path3
}
current = current.parent
} while (current.parent != null)
row.push({
Name: child3.name,
Path: path3
})
for each (child4 in child3.childEntity)
{
if (child4.vimType == "Folder")
{
var current = child4.parent
var path4 = child4.name
do {
var parent = current
if (parent.name != "vm")
{
path4 = parent.name + "\\" + path4
}
current = current.parent
} while (current.parent != null)
row.push({
Name: child4.name,
Path: path4
})
for each (child5 in child4.childEntity)
{
if (child5.vimType == "Folder")
{
var current = child5.parent
var path5 = child5.name
do {
var parent = current
if (parent.name != "vm")
{
path5 = parent.name + "\\" + path5
}
current = current.parent
} while (current.parent != null)
row.push({
Name: child5.name,
Path: path5
})
for each (child6 in child5.childEntity)
{
if (child6.vimType == "Folder")
{
var current = child6.parent
var path6 = child6.name
do {
var parent = current
if (parent.name != "vm")
{
path6 = parent.name + "\\" + path6
}
current = current.parent
} while (current.parent != null)
row.push({
Name: child6.name,
Path: path6
})
for each (child7 in child6.childEntity)
{
if (child7.vimType == "Folder")
{
var current = child7.parent
var path6 = child7.name
do {
var parent = current
if (parent.name != "vm")
{
path7 = parent.name + "\\" + path7
}
current = current.parent
} while (current.parent != null)
row.push({
Name: child7.name,
Path: path7
})
for each (child8 in child7.childEntity)
{
if (child8.vimType == "Folder")
{
var current = child8.parent
var path6 = child8.name
do {
var parent = current
if (parent.name != "vm")
{
path8 = parent.name + "\\" + path8
}
current = current.parent
} while (current.parent != null)
row.push({
Name: child8.name,
Path: path8
})
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
return row
}
vcs = VcPlugin.allSdkConnections
for each (vc in vcs)
{
var dcs = vc.getAllDatacenters()
for each (dc in dcs)
{
System.log("Getting folder path in '"+dc.name+"'...")
var paths = getFolderPath(dc)
for (i = 0; i < paths.length; i++)
{
System.log("Name:- " + paths[i].Name + " Path:- " + paths[i].Path);
}
}
}
如您所见,我已经嵌套了八次子代码。这是一种不好的做法,因为根据环境的不同,任何时候嵌套文件夹的数量都可能多于 8 个。我还试图将每个 child 的 parent 附加到“行”中 array
,所以我想不出如何使用 do-while
.
这是预期的输出 -
[2019-12-05 12:37:31.276] [I] Getting folder path in 'CHA-NX2'...
[2019-12-05 12:37:50.790] [I] Name:- Apps Path:- CHA-NX2\Apps
[2019-12-05 12:37:50.792] [I] Name:- Test Path:- CHA-NX2\Apps\Test
[2019-12-05 12:37:50.794] [I] Name:- HSD Path:- CHA-NX2\Apps\Test\HSD
[2019-12-05 12:37:50.796] [I] Name:- CHD02 Path:- CHA-NX2\Apps\CHD02
[2019-12-05 12:37:50.798] [I] Name:- BlueZone Servers Path:- CHA-NX2\Apps\CHD02\BlueZone Servers
[2019-12-05 12:37:50.799] [I] Name:- Cactus Servers Path:- CHA-NX2\Apps\CHD02\Cactus Servers
[2019-12-05 12:37:50.801] [I] Name:- CognosTM1 Servers Path:- CHA-NX2\Apps\CHD02\CognosTM1 Servers
[2019-12-05 12:37:50.802] [I] Name:- Facets Beta Servers Path:- CHA-NX2\Apps\CHD02\Facets Beta Servers
[2019-12-05 12:37:50.804] [I] Name:- SAS Servers Path:- CHA-NX2\Apps\CHD02\SAS Servers
[2019-12-05 12:37:50.805] [I] Name:- SLX Servers Path:- CHA-NX2\Apps\CHD02\SLX Servers
[2019-12-05 12:37:50.807] [I] Name:- Facets5 Servers Path:- CHA-NX2\Apps\CHD02\Facets5 Servers
[2019-12-05 12:37:50.808] [I] Name:- DB2Apps Servers Path:- CHA-NX2\Apps\CHD02\DB2Apps Servers
[2019-12-05 12:37:50.810] [I] Name:- FHIA Test Servers Path:- CHA-NX2\Apps\CHD02\FHIA Test Servers
[2019-12-05 12:37:50.811] [I] Name:- ISTools Servers Path:- CHA-NX2\Apps\CHD02\ISTools Servers
[2019-12-05 12:37:50.813] [I] Name:- Infoserver Servers Path:- CHA-NX2\Apps\CHD02\Infoserver Servers
[2019-12-05 12:37:50.815] [I] Name:- Hedis 2018 Servers Path:- CHA-NX2\Apps\CHD02\Hedis 2018 Servers
[2019-12-05 12:37:50.816] [I] Name:- FireFox-Chrome Servers Path:- CHA-NX2\Apps\CHD02\FireFox-Chrome Servers
[2019-12-05 12:37:50.818] [I] Name:- Facets Test Servers Path:- CHA-NX2\Apps\CHD02\Facets Test Servers
[2019-12-05 12:37:50.819] [I] Name:- Facets Release2 Servers Path:- CHA-NX2\Apps\CHD02\Facets Release2 Servers
[2019-12-05 12:37:50.823] [I] Name:- PSF Servers Path:- CHA-NX2\Apps\CHD02\PSF Servers
[2019-12-05 12:37:50.825] [I] Name:- Prism Servers Path:- CHA-NX2\Apps\CHD02\Prism Servers
[2019-12-05 12:37:50.827] [I] Name:- CCPulse Servers Path:- CHA-NX2\Apps\CHD02\CCPulse Servers
[2019-12-05 12:37:50.829] [I] Name:- Facets TSIT Servers Path:- CHA-NX2\Apps\CHD02\Facets TSIT Servers
[2019-12-05 12:37:50.831] [I] Name:- Facets Release Servers Path:- CHA-NX2\Apps\CHD02\Facets Release Servers
[2019-12-05 12:37:50.833] [I] Name:- Hedis 2019 Servers Path:- CHA-NX2\Apps\CHD02\Hedis 2019 Servers
[2019-12-05 12:37:50.834] [I] Name:- Facets SUBS Path:- CHA-NX2\Apps\CHD02\Facets SUBS
[2019-12-05 12:37:50.836] [I] Name:- TeamMate Servers Path:- CHA-NX2\Apps\CHD02\TeamMate Servers
[2019-12-05 12:37:50.837] [I] Name:- Standard Servers Path:- CHA-NX2\Apps\CHD02\Standard Servers
[2019-12-05 12:37:50.839] [I] Name:- Facets 2016 Servers Path:- CHA-NX2\Apps\CHD02\Facets 2016 Servers
[2019-12-05 12:37:50.841] [I] Name:- Facets Prod2 Servers Path:- CHA-NX2\Apps\CHD02\Facets Prod2 Servers
[2019-12-05 12:37:50.842] [I] Name:- FHIA DEV Servers Path:- CHA-NX2\Apps\CHD02\FHIA DEV Servers
[2019-12-05 12:37:50.844] [I] Name:- Facets Development Servers Path:- CHA-NX2\Apps\CHD02\Facets Development Servers
[2019-12-05 12:37:50.846] [I] Name:- Templates Path:- CHA-NX2\Apps\Templates
[2019-12-05 12:37:50.847] [I] Name:- Discovered virtual machine Path:- CHA-NX2\Discovered virtual machine
[2019-12-05 12:37:50.849] [I] Name:- Desktops Path:- CHA-NX2\Desktops
[2019-12-05 12:37:50.850] [I] Name:- Persistent Path:- CHA-NX2\Desktops\Persistent
[2019-12-05 12:37:50.852] [I] Name:- Win10 1809 x64 Developer Path:- CHA-NX2\Desktops\Persistent\Win10 1809 x64 Developer
[2019-12-05 12:37:50.853] [I] Name:- Win10 1809 x64 Java Path:- CHA-NX2\Desktops\Persistent\Win10 1809 x64 Java
[2019-12-05 12:37:50.855] [I] Name:- Win10 1809 x64 Standard Path:- CHA-NX2\Desktops\Persistent\Win10 1809 x64 Standard
[2019-12-05 12:37:50.857] [I] Name:- Win10 1709 x64 Java Path:- CHA-NX2\Desktops\Persistent\Win10 1709 x64 Java
[2019-12-05 12:37:50.859] [I] Name:- Imaging EWS Path:- CHA-NX2\Desktops\Persistent\Imaging EWS
[2019-12-05 12:37:50.861] [I] Name:- Allan H Path:- CHA-NX2\Desktops\Persistent\Imaging EWS\Allan H
[2019-12-05 12:37:50.863] [I] Name:- David F Path:- CHA-NX2\Desktops\Persistent\Imaging EWS\David F
[2019-12-05 12:37:50.865] [I] Name:- Jack JC Path:- CHA-NX2\Desktops\Persistent\Imaging EWS\Jack JC
[2019-12-05 12:37:50.867] [I] Name:- Melville P Path:- CHA-NX2\Desktops\Persistent\Imaging EWS\Melville P
[2019-12-05 12:37:50.869] [I] Name:- Swetha B Path:- CHA-NX2\Desktops\Persistent\Imaging EWS\Swetha B
[2019-12-05 12:37:50.871] [I] Name:- Raja T Path:- CHA-NX2\Desktops\Persistent\Imaging EWS\Raja T
[2019-12-05 12:37:50.873] [I] Name:- Tim C Path:- CHA-NX2\Desktops\Persistent\Imaging EWS\Tim C
[2019-12-05 12:37:50.875] [I] Name:- Peter A Path:- CHA-NX2\Desktops\Persistent\Imaging EWS\Peter A
[2019-12-05 12:37:50.876] [I] Name:- Lee G Path:- CHA-NX2\Desktops\Persistent\Imaging EWS\Lee G
[2019-12-05 12:37:50.878] [I] Name:- Sai KV Path:- CHA-NX2\Desktops\Persistent\Imaging EWS\Sai KV
[2019-12-05 12:37:50.880] [I] Name:- Shane M Path:- CHA-NX2\Desktops\Persistent\Imaging EWS\Shane M
[2019-12-05 12:37:50.882] [I] Name:- Vjay E Path:- CHA-NX2\Desktops\Persistent\Imaging EWS\Vjay E
[2019-12-05 12:37:50.884] [I] Name:- Win10 1709 x64 Developer Path:- CHA-NX2\Desktops\Persistent\Win10 1709 x64 Developer
[2019-12-05 12:37:50.886] [I] Name:- Templates Path:- CHA-NX2\Desktops\Persistent\Templates
[2019-12-05 12:37:50.888] [I] Name:- Archive Path:- CHA-NX2\Desktops\Persistent\Templates\Archive
[2019-12-05 12:37:50.890] [I] Name:- Maintenance Devices Path:- CHA-NX2\Desktops\Persistent\Templates\Maintenance Devices
[2019-12-05 12:37:50.892] [I] Name:- Win10 x64 Standard Path:- CHA-NX2\Desktops\Persistent\Win10 x64 Standard
[2019-12-05 12:37:50.894] [I] Name:- Connect2Dev.com Path:- CHA-NX2\Desktops\Persistent\Connect2Dev.com
[2019-12-05 12:37:50.896] [I] Name:- Win7 x86 Developer Path:- CHA-NX2\Desktops\Persistent\Win7 x86 Developer
[2019-12-05 12:37:50.897] [I] Name:- Win7 x64 Developer Path:- CHA-NX2\Desktops\Persistent\Win7 x64 Developer
[2019-12-05 12:37:50.899] [I] Name:- Win10 x64 Java Path:- CHA-NX2\Desktops\Persistent\Win10 x64 Java
[2019-12-05 12:37:50.900] [I] Name:- Win7 x64 IIB Path:- CHA-NX2\Desktops\Persistent\Win7 x64 IIB
[2019-12-05 12:37:50.902] [I] Name:- Win10 Path:- CHA-NX2\Desktops\Persistent\Win10
[2019-12-05 12:37:50.903] [I] Name:- 7.12 Path:- CHA-NX2\Desktops\Persistent\7.12
[2019-12-05 12:37:50.905] [I] Name:- Win7 x64 RAD Path:- CHA-NX2\Desktops\Persistent\Win7 x64 RAD
[2019-12-05 12:37:50.906] [I] Name:- Win7 x86 Standard Path:- CHA-NX2\Desktops\Persistent\Win7 x86 Standard
[2019-12-05 12:37:50.908] [I] Name:- Win10 1703 x64 Standard Path:- CHA-NX2\Desktops\Persistent\Win10 1703 x64 Standard
[2019-12-05 12:37:50.909] [I] Name:- Win10 x64 Developer Path:- CHA-NX2\Desktops\Persistent\Win10 x64 Developer
[2019-12-05 12:37:50.911] [I] Name:- Win7 x64 Standard Path:- CHA-NX2\Desktops\Persistent\Win7 x64 Standard
[2019-12-05 12:37:50.912] [I] Name:- Provisioned Path:- CHA-NX2\Desktops\Provisioned
[2019-12-05 12:37:50.914] [I] Name:- Windows 10 Deep Security Path:- CHA-NX2\Desktops\Provisioned\Windows 10 Deep Security
[2019-12-05 12:37:50.916] [I] Name:- PackagingVMs Path:- CHA-NX2\Desktops\Provisioned\PackagingVMs
[2019-12-05 12:37:50.917] [I] Name:- Windows 10 Standard Path:- CHA-NX2\Desktops\Provisioned\Windows 10 Standard
[2019-12-05 12:37:50.919] [I] Name:- Windows 7 Dakota Path:- CHA-NX2\Desktops\Provisioned\Windows 7 Dakota
[2019-12-05 12:37:50.920] [I] Name:- New Folder Path:- CHA-NX2\Desktops\Provisioned\Windows 7 Dakota\New Folder
[2019-12-05 12:37:50.922] [I] Name:- Windows 7 eCopy Path:- CHA-NX2\Desktops\Provisioned\Windows 7 eCopy
[2019-12-05 12:37:50.924] [I] Name:- Windows 7 Pilot Desktops Path:- CHA-NX2\Desktops\Provisioned\Windows 7 Pilot Desktops
[2019-12-05 12:37:50.926] [I] Name:- Windows 7 Standard - Appsense Test Path:- CHA-NX2\Desktops\Provisioned\Windows 7 Standard - Appsense Test
[2019-12-05 12:37:50.928] [I] Name:- Windows 7 Hedis Path:- CHA-NX2\Desktops\Provisioned\Windows 7 Hedis
[2019-12-05 12:37:50.929] [I] Name:- Windows 7 Standard DSA Path:- CHA-NX2\Desktops\Provisioned\Windows 7 Standard DSA
[2019-12-05 12:37:50.931] [I] Name:- Windows 7 Standard - Verint Dev Path:- CHA-NX2\Desktops\Provisioned\Windows 7 Standard - Verint Dev
[2019-12-05 12:37:50.933] [I] Name:- Windows 7 Standard OfficeScan Path:- CHA-NX2\Desktops\Provisioned\Windows 7 Standard OfficeScan
[2019-12-05 12:37:50.935] [I] Name:- Windows 10 SQA Path:- CHA-NX2\Desktops\Provisioned\Windows 10 SQA
[2019-12-05 12:37:50.937] [I] Name:- Temp Path:- CHA-NX2\Desktops\Temp
[2019-12-05 12:37:50.939] [I] Name:- BSOD Path:- CHA-NX2\Desktops\Temp\BSOD
[2019-12-05 12:37:50.941] [I] Name:- Templates Path:- CHA-NX2\Desktops\Templates
[2019-12-05 12:37:50.943] [I] Getting folder path in 'CHA-N02'...
[2019-12-05 12:38:02.140] [I] Name:- ALL BCBST Path:- CHA-N02\ALL BCBST
[2019-12-05 12:38:02.142] [I] Name:- CareAdvance Path:- CHA-N02\ALL BCBST\CareAdvance
[2019-12-05 12:38:02.143] [I] Name:- Citrix Path:- CHA-N02\ALL BCBST\Citrix
[2019-12-05 12:38:02.145] [I] Name:- Health Mason Path:- CHA-N02\ALL BCBST\Citrix\Health Mason
[2019-12-05 12:38:02.147] [I] Name:- Infrastructure Path:- CHA-N02\ALL BCBST\Citrix\Infrastructure
[2019-12-05 12:38:02.148] [I] Name:- Controllers Path:- CHA-N02\ALL BCBST\Citrix\Infrastructure\Controllers
[2019-12-05 12:38:02.150] [I] Name:- Admin Path:- CHA-N02\ALL BCBST\Citrix\Infrastructure\Admin
[2019-12-05 12:38:02.151] [I] Name:- Director Path:- CHA-N02\ALL BCBST\Citrix\Infrastructure\Director
[2019-12-05 12:38:02.153] [I] Name:- License Path:- CHA-N02\ALL BCBST\Citrix\Infrastructure\License
[2019-12-05 12:38:02.154] [I] Name:- Provisioning Path:- CHA-N02\ALL BCBST\Citrix\Infrastructure\Provisioning
[2019-12-05 12:38:02.156] [I] Name:- LoginVSI Path:- CHA-N02\ALL BCBST\Citrix\Infrastructure\LoginVSI
[2019-12-05 12:38:02.158] [I] Name:- ShareFile Controllers Path:- CHA-N02\ALL BCBST\Citrix\Infrastructure\ShareFile Controllers
[2019-12-05 12:38:02.159] [I] Name:- FAS Path:- CHA-N02\ALL BCBST\Citrix\Infrastructure\FAS
[2019-12-05 12:38:02.161] [I] Name:- StoreFront Path:- CHA-N02\ALL BCBST\Citrix\Infrastructure\StoreFront
[2019-12-05 12:38:02.162] [I] Name:- Disaster Recovery Servers Path:- CHA-N02\ALL BCBST\Disaster Recovery Servers
[2019-12-05 12:38:02.164] [I] Name:- Dynamics Servers Path:- CHA-N02\ALL BCBST\Dynamics Servers
[2019-12-05 12:38:02.165] [I] Name:- Enterprise Monitoring Servers Path:- CHA-N02\ALL BCBST\Enterprise Monitoring Servers
[2019-12-05 12:38:02.167] [I] Name:- Fax Path:- CHA-N02\ALL BCBST\Fax
[2019-12-05 12:38:02.169] [I] Name:- Fax Servers Path:- CHA-N02\ALL BCBST\Fax Servers
[2019-12-05 12:38:02.170] [I] Name:- File Servers Path:- CHA-N02\ALL BCBST\File Servers
[2019-12-05 12:38:02.172] [I] Name:- ICD10 Servers Path:- CHA-N02\ALL BCBST\ICD10 Servers
[2019-12-05 12:38:02.173] [I] Name:- Imaging Servers Path:- CHA-N02\ALL BCBST\Imaging Servers
[2019-12-05 12:38:02.175] [I] Name:- Active Directory Path:- CHA-N02\ALL BCBST\Active Directory
[2019-12-05 12:38:02.177] [I] Name:- bcbstbeta.com Path:- CHA-N02\ALL BCBST\Active Directory\bcbstbeta.com
[2019-12-05 12:38:02.178] [I] Name:- bcbstdev.com Path:- CHA-N02\ALL BCBST\Active Directory\bcbstdev.com
[2019-12-05 12:38:02.180] [I] Name:- bcbst.com Path:- CHA-N02\ALL BCBST\Active Directory\bcbst.com
[2019-12-05 12:38:02.181] [I] Name:- bcbstsit.com Path:- CHA-N02\ALL BCBST\Active Directory\bcbstsit.com
[2019-12-05 12:38:02.183] [I] Name:- bcbsttest.com Path:- CHA-N02\ALL BCBST\Active Directory\bcbsttest.com
[2019-12-05 12:38:02.185] [I] Name:- dmz.bcbst.com Path:- CHA-N02\ALL BCBST\Active Directory\dmz.bcbst.com
[2019-12-05 12:38:02.186] [I] Name:- nonprod.com Path:- CHA-N02\ALL BCBST\Active Directory\nonprod.com
[2019-12-05 12:38:02.188] [I] Name:- sdmz.bcbst.com Path:- CHA-N02\ALL BCBST\Active Directory\sdmz.bcbst.com
[2019-12-05 12:38:02.190] [I] Name:- Facets Servers Path:- CHA-N02\ALL BCBST\Facets Servers
最佳答案
只是一种抽象方法(我仍然怀疑,代码是 Javascript 而不是 Java)。
这是yopur代码的一种模式,你在其中迭代一些数据,检查类型并迭代路径。最后,您将一个新对象放入 row
。
for (child in parentFolder.childEntity) { // *in* maybe wrong, just to mention ...
if (child.vimType == "Folder") {
var current = child.parent
var path = child.name
do {
var parent = current
if (parent.name != "vm") path = parent.name + "\\" + path;
current = current.parent
} while (current.parent != null)
row.push({ Name: child.name, Path: path });
// next same pattern with child.childEntity
}
}
您可以将此模式转换为一个函数,并移交用于迭代的数据和目标数组 row
(或者如果 this 是嵌套函数,则可能不会)。
然后进行否定检查并在没有嵌套 block 的情况下继续循环。
然后获取路径值并推送对象。
最后退出递归调用或用新数据再次调用函数。在您的代码中,您使用了嵌套方法,在这里,您可以检查 child.childEntity
是否为假。
function iter(data, row) {
for (child in data) {
if (child.vimType !== "Folder") continue;
var current = child.parent
var path = child.name
do {
var parent = current;
if (parent.name !== "vm") path = parent.name + "\\" + path;
current = current.parent
} while (current.parent != null)
row.push({ Name: child.name, Path: path });
if (!child.childEntity) continue;
iter(child.childEntity, row);
}
}
// call
iter(parentFolder.childEntity, row);
关于javascript - 简化JS中嵌套的父子代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59200966/
我有一个 html 格式的表单: 我需要得到 JavaScript在value input 字段执行,但只能通过表单的 submit .原因是页面是一个模板所以我不控制它(不能有
我管理的论坛是托管软件,因此我无法访问源代码,我只能向页面添加 JavaScript 来实现我需要完成的任务。 我正在尝试用超链接替换所有页面上某些文本关键字的第一个实例。我还根据国家/地区代码对这些
我正在使用 JS 打开新页面并将 HTML 代码写入其中,但是当我尝试使用 document.write() 在新页面中编写 JS 时功能不起作用。显然,一旦看到 ,主 JS 就会关闭。用于即将打开的
提问不是为了解决问题,提问是为了更好地理解系统 专家!我知道每当你将 javascript 代码输入 javascript 引擎时,它会立即由 javascript 引擎执行。由于没有看过Engi
我在一个文件夹中有两个 javascript 文件。我想将一个变量的 javascript 文件传递到另一个。我应该使用什么程序? 最佳答案 window.postMessage用于跨文档消息。使
我有一个练习,我需要输入两个输入并检查它们是否都等于一个。 如果是 console.log 正则 console.log false 我试过这样的事情: function isPositive(fir
我正在做一个Web应用程序,计划允许其他网站(客户端)在其页面上嵌入以下javascript: 我的网络应用程序位于 http://example.org 。 我不能假设客户端网站的页面有 JQue
目前我正在使用三个外部 JS 文件。 我喜欢将所有三个 JS 文件合而为一。 尽一切可能。我创建 aio.js 并在 aio.js 中 src="https://code.jquery.com/
我有例如像这样的数组: var myArray = []; var item1 = { start: '08:00', end: '09:30' } var item2 = {
所以我正在制作一个 Chrome 扩展,它使用我制作的一些 TamperMonkey 脚本。我想要一个“主”javascript 文件,您可以在其中包含并执行其他脚本。我很擅长使用以下行将其他 jav
我有 A、B html 和 A、B javascript 文件。 并且,如何将 A JavaScript 中使用的全局变量直接移动到 B JavaScript 中? 示例 JavaScript) va
我需要将以下整个代码放入名为 activate.js 的 JavaScript 中。你能告诉我怎么做吗? var int = new int({ seconds: 30, mark
我已经为我的 .net Web 应用程序创建了母版页 EXAMPLE1.Master。他们的 I 将值存储在 JavaScript 变量中。我想在另一个 JS 文件中检索该变量。 示例1.大师:-
是否有任何库可以用来转换这样的代码: function () { var a = 1; } 像这样的代码: function () { var a = 1; } 在我的浏览器中。因为我在 Gi
我收到语法缺失 ) 错误 $(document).ready(function changeText() { var p = document.getElementById('bidp
我正在制作进度条。它有一个标签。我想调整某个脚本完成的标签。在找到可能的解决方案的一些答案后,我想出了以下脚本。第一个启动并按预期工作。然而,第二个却没有。它出什么问题了?代码如下: HTML:
这里有一个很简单的问题,我简单的头脑无法回答:为什么我在外部库中加载时,下面的匿名和onload函数没有运行?我错过了一些非常非常基本的东西。 Library.js 只有一行:console.log(
我知道 javascript 是一种客户端语言,但如果实际代码中嵌入的 javascript 代码以某种方式与在控制台上运行的代码不同,我会尝试找到答案。让我用一个例子来解释它: 我想创建一个像 Mi
我如何将这个内联 javascript 更改为 Unobtrusive JavaScript? 谢谢! 感谢您的回答,但它不起作用。我的代码是: PHP js文件 document.getElem
我正在寻找将简单的 JavaScript 对象“转储”到动态生成的 JavaScript 源代码中的最优雅的方法。 目的:假设我们有 node.js 服务器生成 HTML。我们在服务器端有一个对象x。
我是一名优秀的程序员,十分优秀!