• <sub id="h4knl"><ol id="h4knl"></ol></sub>
    <sup id="h4knl"></sup>
      <sub id="h4knl"></sub>

      <sub id="h4knl"><ol id="h4knl"><em id="h4knl"></em></ol></sub><s id="h4knl"></s>
      1. <strong id="h4knl"></strong>

      2. 調(diào)用javascript

        時(shí)間:2024-08-02 06:04:56 JavaScript 我要投稿
        • 相關(guān)推薦

        調(diào)用javascript

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

          Java語言作為靜態(tài)面向?qū)ο缶幊陶Z言的代表,極好地實(shí)現(xiàn)了面向?qū)ο罄碚摚试S程序員以優(yōu)雅的思維方式進(jìn)行復(fù)雜的編程。以下是小編為大家搜索整理的從零碼起調(diào)用javascript,希望能給大家?guī)韼椭?更多精彩內(nèi)容請(qǐng)及時(shí)關(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));

          }

          }

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

          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;} ;

          }

        《&.doc》
        将本文的Word文档下载到电脑,方便收藏和打印
        推荐度:
        点击下载文档

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

        對(duì)javascript的理解08-08

        java調(diào)用cmd命令01-29

        常用的JavaScript模式09-22

        Javascript的this用法簡述08-15

        Windows網(wǎng)絡(luò)診斷怎么調(diào)用10-02

        JavaScript學(xué)習(xí)筆記08-24

        JavaScript 基礎(chǔ)教學(xué)09-29

        JavaScript的課堂講解09-03

        JavaScript常用方法匯總10-25

        java程序中如何調(diào)用linux命令08-27

        在线咨询
        国产高潮无套免费视频_久久九九兔免费精品6_99精品热6080YY久久_国产91久久久久久无码
      3. <sub id="h4knl"><ol id="h4knl"></ol></sub>
        <sup id="h4knl"></sup>
          <sub id="h4knl"></sub>

          <sub id="h4knl"><ol id="h4knl"><em id="h4knl"></em></ol></sub><s id="h4knl"></s>
          1. <strong id="h4knl"></strong>

          2. 亚洲中文字幕在线最新不卡 | 亚洲精品国产精品乱码无卡 | 日韩精品午夜视频一区二区 | 婷婷中文字幕一区二区三区 | 亚洲欧美精品精品aⅴ | 五月开心亚洲综合在线 |

            調(diào)用javascript

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

              Java語言作為靜態(tài)面向?qū)ο缶幊陶Z言的代表,極好地實(shí)現(xiàn)了面向?qū)ο罄碚摚试S程序員以優(yōu)雅的思維方式進(jìn)行復(fù)雜的編程。以下是小編為大家搜索整理的從零碼起調(diào)用javascript,希望能給大家?guī)韼椭?更多精彩內(nèi)容請(qǐng)及時(shí)關(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));

              }

              }

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

              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;} ;

              }