Home > Web Front-end > JS Tutorial > JavaScript interacts with .NET applications

JavaScript interacts with .NET applications

高洛峰
Release: 2016-11-26 13:37:42
Original
1571 people have browsed it

JavaScript interacts with .NET applications_Experiment 1

C# calls JavaScript functions
                                                                                                                                                                           to . A few examples are given below to facilitate everyone’s learning and communication.

There are many JavaScript engines currently, including Google’s Google Chrome V8, Noesis.Javascript, Jurassic.ScriptEngine and so on. As a result of the test, Jurassic.ScriptEngine is more convenient.

The following takes Jurassic.ScriptEngine as an example to introduce a few small examples.

Example 1, calling JavaScript functions in C#

(1) Create a new C# Windows project

(2) Reference the Jurassic library

The picture after the reference is completed:

JavaScript interacts with .NET applications

(3) Add 2 TextBox and 1 Button on WinForm. X TextBox is used to enter the JS code, and the results displayed by the JS calculation. The interface layout is as shown in the figure: The corresponding code is as follows: The corresponding code

              var is a weakly typed object in C#, newly added since the .NET3.5 version. Detailed instructions can be found on MSDN.引 First load the JS code in Textbox1 through the script engine, and then call the C#call to the program that has been loaded to the JS engine by calling the global function. JavaScript interacts with .NET applications

JS code:

                                                                                                                                          

JS code: JavaScript interacts with .NET applications

function add (a,b)

{

Return (a+b)*2;

}JavaScript interacts with .NET applications

function main(a, b)

{

var x=add(a,b);

JavaScript interacts with .NET applications return x;

}

Running effect (2)

Summary:

in the script.

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template