1. <tt id="5hhch"><source id="5hhch"></source></tt>
    1. <xmp id="5hhch"></xmp>

  2. <xmp id="5hhch"><rt id="5hhch"></rt></xmp>

    <rp id="5hhch"></rp>
        <dfn id="5hhch"></dfn>

      1. 調(diào)用javascript

        時間:2020-11-23 16:40:08 JavaScript 我要投稿

        調(diào)用javascript

          【提要】本篇《從零碼起調(diào)用javascript》特別為需要編程學(xué)習(xí)的朋友收集整理的.,僅供參考。內(nèi)容如下:

          Java語言作為靜態(tài)面向?qū)ο缶幊陶Z言的代表,極好地實現(xiàn)了面向?qū)ο罄碚,允許程序員以優(yōu)雅的思維方式進行復(fù)雜的編程。以下是小編為大家搜索整理的從零碼起調(diào)用javascript,希望能給大家?guī)韼椭?更多精彩內(nèi)容請及時關(guān)注我們考試網(wǎng)!

          package co.test;

          import java.io.FileReader;

          import java.io.LineNumberReader;

          import org.mozilla.javascript.Context;

          import org.mozilla.javascript.Function;

          import org.mozilla.javascript.Scriptable;

          public class JSExploration

          {

          private Context cx;

          private Scriptable scope;

          public JSExploration()

          {

          this.cx = Context.enter();

          this.scope = cx.initStandardObjects();

          }

          public Object runJavaScript(String filename)

          {

          String jsContent = this.getJsContent(filename);

          Object result = cx.evaluateString(scope, jsContent, filename, 1, null);

          return result;

          }

          private String getJsContent(String filename)

          {

          LineNumberReader reader;

          try

          {

          reader = new LineNumberReader(new FileReader(filename));

          String s = null;

          StringBuffer sb = new StringBuffer();

          while ((s = reader.readLine()) != null)

          {

          sb.append(s).append(" ");

          }

          return sb.toString();

          }

          catch (Exception e)

          {

          // TODO Auto-generated catch block

          e.printStackTrace();

          return null;

          }

          }

          public Scriptable getScope()

          {

          return scope;

          }

          public static void main(String[] args)

          {

          String filename = System.getProperty("user.dir") + "/jsmap.js";

          JSExploration jsExploration = new JSExploration();

          Object result = jsExploration.runJavaScript(filename);

          Scriptable scope = jsExploration.getScope();

          Function sum = (Function) scope.get("sum", scope);

          Function isPrime = (Function)sum.call(Context.getCurrentContext(), scope, sum, new Object[] {2,8});

          Object ss = isPrime.call(Context.getCurrentContext(), sum, isPrime, new Object[] {2,8});

          System.out.println(Context.toString(ss));

          }

          }

          試驗了一個java 調(diào)用 javascript 的例子,如果把jsmap.js中的與this 有關(guān)的代碼注銷的話程序就可以正常運行。不住銷掉的話就會報個運行時錯誤。。。

          js 代碼如下(有關(guān)this 的代碼已注銷):

          function sum(x, y) {

          // this.formulaeObject = null;

          // this.formulaeObject["vager"] = function (c, d) {

          // return (c + d)/2;

          // };

          var vager = 1000;

          return function (x,y){return x + y + vager;} ;

          }

        【調(diào)用javascript】相關(guān)文章:

        1.javascript數(shù)組使用調(diào)用方法

        2.分析JavaScript函數(shù)的調(diào)用模式

        3.JavaScript中調(diào)用函數(shù)的4種方式

        4.c#和javascript函數(shù)相互調(diào)用示例

        5.Java如何調(diào)用WebService

        6.Javascript模板

        7.Windows網(wǎng)絡(luò)診斷怎么調(diào)用

        8.java調(diào)用cmd命令大全

        国产高潮无套免费视频_久久九九兔免费精品6_99精品热6080YY久久_国产91久久久久久无码

        1. <tt id="5hhch"><source id="5hhch"></source></tt>
          1. <xmp id="5hhch"></xmp>

        2. <xmp id="5hhch"><rt id="5hhch"></rt></xmp>

          <rp id="5hhch"></rp>
              <dfn id="5hhch"></dfn>