Home >Web Front-end >JS Tutorial >Javascript and vbscript data sharing_javascript skills

Javascript and vbscript data sharing_javascript skills

WBOY
WBOYOriginal
2016-05-16 19:21:291536browse

If there are any mistakes, please point them out, thank you

1. Ordinary global variables
In the browser, there are many ways to reference a global variable. You can reference the variable directly or use window. variable to refer to global variables. The reason is that global variables belong to the window form, but every time a new window is opened, the browser will automatically clear the previous variables (that is, each new page is a "clear" "web page", so previously defined variables cannot be referenced in a newly opened window. If you want to reference them, you can obtain them in a different direction, such as by passing parameters in the URL, but this is a story later) For example:





Output result:
this is a global var.
this is a global var.

2. vbs References to js objects (non-prototype objects) and functions
can be directly referenced: object name. Attribute name






Output result:
change
hange

When js is prototype type, vbs can use the following method to access members of js






3. To call a class in vbs in js, you can first create an instance in vbs. js can access the members of vbs through this instance.





Output result:
blueDestiny

4. When js calls the array defined by vbs, you can directly use the subscript to get the first The value of several elements.






Output result:
blue
destiny

However, how to convert a vbs array into a js array Woolen cloth? You can use the VBArray() object of js and the toArray() method. It is worth noting that the toArray() method results in a one-dimensional array:






Output results:
1 2 3
4 5 6
7 8 9
1 2 3 4 5 6 7 8 9

5. Convert js array to vbs Array:
Get the array length of js, you can directly use the length attribute to get

<script> <BR>var global = "this is a global var." <BR></script> <script> <BR><!-- <BR>alert(window.global) <BR>alert(global) <BR>//--> <BR></script><script> <BR><!-- <BR>function obj(){}; <BR>obj.string="test"; <BR>obj.replacec=function(s){return s.replace(/c/,"")}; <BR>//--> <BR></script> <script> <BR><!-- <BR>alert(obj.string) <BR>obj.string="change" <BR>alert(obj.string) <BR>alert(obj.replacec(obj.string)) <BR>//--> <BR></script><script> <BR><!-- <BR>function myClass(s) <BR>{ <BR> this.s=s <BR> return this; <BR>}; <BR>myClass.prototype.output=function() <BR>{ <BR> alert(this.s); <BR>} <BR>var obj=new myClass("blueDestiny"); <BR>//--> <BR></script>Output result: <script> <BR><!-- <BR>obj.output() <BR>//--> <BR></script>2 <script> <BR><!-- <BR>class myClass <BR> public s <BR> public sub alertstring() <BR> alert(s) <BR> end sub <BR>end class <BR>set obj=new myClass <BR>//--> <BR></script><script> <BR><!-- <BR>obj.s="blueDestiny" <BR>obj.alertstring() <BR>//--> <BR></script>If you want to access the array elements of js through subscripts, you will not be able to get it, but you can use the existing methods: join() (method in js) and Split() <script> <BR>dim a(2) <BR>a(0)="blue" <BR>a(1)="destiny" <BR></script><script> <BR><!-- <BR>alert(a(0)) <BR>alert(a(1)) <BR>//--> <BR></script><script> <BR><!-- <BR>Function CreateVBArray() <BR> Dim i, j, k <BR> Dim a(2, 2) <BR> '初始化二维数组 <BR> k = 1 <BR> For i = 0 To 2 <BR> For j = 0 To 2 <BR> a(j, i) = k <BR> document.writeln(k) <BR> k = k + 1 <BR> Next <BR> document.writeln("<BR>") <BR> Next <BR> CreateVBArray = a <BR>End Function <BR>--> <BR></script> <script> <BR><!-- <BR>function VBArrayTest(vbarray) <BR>{ <BR> //调用VBArray()对象,将vbs数组转化为js的数组并调用toArray()方法得到一维数组。 <BR> var a = new VBArray(vbarray); <BR> var b = a.toArray(); <BR> var i; <BR> for (i = 0; i < 9; i++) <BR> { <BR> document.writeln(b[i]); <BR> } <br><br>} <BR>VBArrayTest(CreateVBArray()); <BR>--> <BR></script><script> <BR><!-- <BR>var arr=["blue","Destiny"]; <BR>//--> <BR></script>Output result<script> <BR><!-- <BR>alert(arr.length) <BR>//--> <BR></script>blue <script> <BR><!-- <BR>'注:这里不可用vbs的join(arr,",")方法,实际上这里所用到的是js里的join方法,并且为vbs的 <BR>vbarr=arr.join(",") <BR>vbarr=split(vbarr,",") <BR>alert(vbarr(0)) <BR>alert(vbarr(1)) <BR>//--> <BR></script>Destiny

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn