热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

VBScript:在DOM元素中使用变量-VBScript:UsingavariablewithinaDOMelement

ImlookingtouseaVBScriptvariablewithinareferencetoaDOMelementforaweb-appImbuildin

I'm looking to use a Vbscript variable within a reference to a DOM element for a web-app I'm building. Here's a brief excerpt of the affected area of code:

我正在寻找在我正在构建的Web应用程序的DOM元素的引用中使用Vbscript变量。以下是受影响的代码区域的简短摘录:

dim num
num = CInt(document.myform.i.value)
dim x
x = 0
dim orders(num)
For x = 0 To num
    orders(x) = document.getElementById("order" & x).value
    objFile.writeLine(orders(x))
Next

This is my first venture into Vbscript, and I've not been able to find any methods of performing this type of action online. As you can see in the above code, I'm trying to create an array (orders). This array can have any number of values, but that number will be specified in document.myform.i.value. So the For loop cycles through all text inputs with an ID of order+x (ie, order0, order1, order2, order3, order4, etc. up to num)

这是我第一次进入Vbscript,我无法找到任何在线执行此类操作的方法。正如您在上面的代码中看到的,我正在尝试创建一个数组(orders)。此数组可以包含任意数量的值,但该数字将在document.myform.i.value中指定。所以For循环遍历所有文本输入,ID为order + x(即order0,order1,order2,order3,order4等,最多为num)

It seems to be a problem with my orders(x) line, I don't think it recognizes what I mean by getElementById("order" & x), and I'm not sure exactly how to do such a thing. Anyone have any suggestions? It would be much appreciated!

这似乎是我的订单(x)行的一个问题,我认为它不能识别我的意思getElementById(“order”&x),我不确定如何做这样的事情。有人有什么建议吗?非常感谢!

4 个解决方案

#1


1  

I was able to get this working. Thanks to both of you for your time and input. Here is what solved it for me:

我能够让这个工作。感谢你们两位时间和投入。以下是为我解决的问题:

Rather than using

而不是使用

document.getElementById("order" & x).value

I set the entire ID as a variable:

我将整个ID设置为变量:

temp = "order" & x
document.getElementById(temp).value

It seems to be working as expected. Again, many thanks for the time and effort on this!

它似乎按预期工作。再次,非常感谢您花时间和精力!

#2


0  

I can only assume that this is client side Vbscript as document.getElementById() isn't accessible from the server.

我只能假设这是客户端Vbscript,因为无法从服务器访问document.getElementById()。

try objFile.writeLine("order" & x), then check the source to make sure all the elements are in the document.

尝试objFile.writeLine(“order”&x),然后检查源以确保所有元素都在文档中。

[As I can't put code in comments...] That is strange. It looks to me like everything should be working.

[因为我不能把代码放在评论中......]这很奇怪。在我看来,一切都应该有效。

Only other thing I can think of is: change

只有我能想到的其他事情是:改变

orders(x) = document.getElementById("order" & x).value
objFile.writeLine(orders(x))

to

orders(x) = document.getElementById("order" & x)
objFile.writeLine(orders(x).value)

#3


0  

It looks as if you're mixing client vs server-side code.

看起来好像是在混合客户端代码和服务器端代码。

objFile.writeLine(orders(x))

That is Vbscript to write to a file, which you can only do on the server.

这是写入文件的Vbscript,您只能在服务器上执行此操作。

document.getElementById

This is client-size code that is usually executed in Javascript. You can use Vbscript on IE on the client, but rarely does anyone do this.

这是通常在Javascript中执行的客户端大小的代码。您可以在客户端上使用IE上的Vbscript,但很少有人这样做。

On the server you'd usually refer to form fields that were part of a form tag, not DOM elements, (assuming you're using classic ASP) using request("formFieldName").

在服务器上,您通常使用request(“formFieldName”)来引用作为表单标记的一部分的表单字段,而不是DOM元素(假设您使用的是经典ASP)。

To make server-side stuff appear on the client (when you build a page) you'd embed it in your HTML like this:

为了使服务器端的东西出现在客户端上(当你构建一个页面时),你将它嵌入你的HTML中,如下所示:

<% = myVariable %>

or like this (as part of a code block):

或者像这样(作为代码块的一部分):

document.write myVariable

#4


0  

Don't you need to change your loop slightly?

你不需要稍微改变你的循环吗?

For x = 0 To num - 1

E.G. With 4 items you need to iterate from 0 to 3.

例如。有4个项目,您需要从0迭代到3。


推荐阅读
author-avatar
mobiledu2502877091
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有