Home > Article > Web Front-end > HTML page, test JS call to C function
The following is an HTML page for you to test a simple example of JS calling C functions. It’s pretty good. I’ll share it with you now and give it as a reference. Come and take a look together
Note it here so you can check it when you need to use it later!
<HTML> <HEAD> <META NAME="GENERATOR" Content="Microsoft Visual Studio"> <meta http-equiv="content-type" content="text/html;charset=gbk"> <TITLE>HTML页面,测试JS对C函数的调用</TITLE> </HEAD> <BODY> <input type="button" value="测试JS对C++无参函数的调用(Window Binding)" onclick="javascript:testCallFunc()" /> <br/><hr /><br /> <input type="button" value="测试JS调用多参数C++函数(Window Binding)" onclick="javascript: testCallFunc2()" /><input id="func2_input1" type="text" value="这里输入参数1" onclick=" if (this.value == '这里输入参数1') { this.value = '' }" onblur="if(this.value==''){this.value='defaultValue'}" /><input id="func2_input2" type="text" value="这里输入参数2" onclick=" if (this.value == '这里输入参数2') { this.value = '' }" onblur="if(this.value==''){this.value='defaultValue'}"/> <br /><hr /><br /> <input type="button" value="测试,调用C++函数修改JS Window对象属性(Window Binding)" onclick="javascript: testCallFunc3()" /><input id="func3_input" type="text" value="这里输入全局变量的值" onclick=" if (this.value == '这里输入全局变量的值') { this.value = '' }" onblur="if(this.value==''){this.value='defaultValue'}" /> <br /><hr/><br /> <input type="button" value="测试取C++在JS Window对象中设置的属性(Window Binding)" onclick="javascript:testGetGlobalVar()" /> <br /><hr /><br /> <input type="button" value="测试JS调用多参数C++函数(扩展方式)" onclick="javascript: alert('测试JS调用多参数C++函数(扩展方式)=>' + kagulaTest.myfunc(document.getElementById('func2_input1').value, document.getElementById('func2_input2').value))"/> <br /><hr /><br /> </BODY> </HTML> <script> //http://www.w3schools.com/jsref/event_onclick.asp //document.write('Hello World!<br/>'); //测试JS调用C++,无参函数 function testCallFunc() { alert(window.myKagulaFunc()); } //测试JS调用C++,带两个参数函数 function testCallFunc2() { var arg1 = document.getElementById("func2_input1").value; var arg2 = document.getElementById("func2_input2").value; alert(window.myKagulaFunc2(arg1,arg2)); //正确返回"head and tail"字符串。 } function testCallFunc3() { var oldValue = window.myKagulaVal; var arg = document.getElementById("func3_input").value; window.myKagulaFunc3(arg); var newValue = window.myKagulaVal; alert("新的值:" + newValue + "\r\n老的值:" + oldValue); } //测试JS读取C++设置的变量 function testGetGlobalVar() { alert(window.myKagulaVal); } //测试c++调用JS function myFunction() { //document.getElementById("demo").style.color = "red"; alert("C++调用JS测试成功!"); } </script>
The above is the detailed content of HTML page, test JS call to C function. For more information, please follow other related articles on the PHP Chinese website!