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

Javascript and vbscript data sharing_javascript skills

May 16, 2016 pm 07:21 PM

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 of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Replace String Characters in JavaScript Replace String Characters in JavaScript Mar 11, 2025 am 12:07 AM

Replace String Characters in JavaScript

jQuery Check if Date is Valid jQuery Check if Date is Valid Mar 01, 2025 am 08:51 AM

jQuery Check if Date is Valid

jQuery get element padding/margin jQuery get element padding/margin Mar 01, 2025 am 08:53 AM

jQuery get element padding/margin

10 jQuery Accordions Tabs 10 jQuery Accordions Tabs Mar 01, 2025 am 01:34 AM

10 jQuery Accordions Tabs

10 Worth Checking Out jQuery Plugins 10 Worth Checking Out jQuery Plugins Mar 01, 2025 am 01:29 AM

10 Worth Checking Out jQuery Plugins

HTTP Debugging with Node and http-console HTTP Debugging with Node and http-console Mar 01, 2025 am 01:37 AM

HTTP Debugging with Node and http-console

jquery add scrollbar to div jquery add scrollbar to div Mar 01, 2025 am 01:30 AM

jquery add scrollbar to div

Custom Google Search API Setup Tutorial Custom Google Search API Setup Tutorial Mar 04, 2025 am 01:06 AM

Custom Google Search API Setup Tutorial

See all articles