Home  >  Article  >  Web Front-end  >  HTML page, test JS call to C function

HTML page, test JS call to C function

不言
不言Original
2018-06-05 15:36:281805browse

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 == &#39;这里输入参数1&#39;) { this.value = &#39;&#39; }" onblur="if(this.value==&#39;&#39;){this.value=&#39;defaultValue&#39;}" /><input id="func2_input2" type="text" value="这里输入参数2" onclick="  if (this.value == &#39;这里输入参数2&#39;) { this.value = &#39;&#39; }" onblur="if(this.value==&#39;&#39;){this.value=&#39;defaultValue&#39;}"/>
  <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 == &#39;这里输入全局变量的值&#39;) { this.value = &#39;&#39; }" onblur="if(this.value==&#39;&#39;){this.value=&#39;defaultValue&#39;}" />
  <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(&#39;测试JS调用多参数C++函数(扩展方式)=>&#39; + kagulaTest.myfunc(document.getElementById(&#39;func2_input1&#39;).value, document.getElementById(&#39;func2_input2&#39;).value))"/>
  <br /><hr /><br />
</BODY>
</HTML>


<script>
  //http://www.w3schools.com/jsref/event_onclick.asp
  //document.write(&#39;Hello World!<br/>&#39;);  
  //测试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!

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