如何将 JavaScript 变量发送到 Java 小程序 [英] How to send JavaScript variables to Java applet

查看:36
本文介绍了如何将 JavaScript 变量发送到 Java 小程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 JavaScript 函数,它是:

I have a JavaScript function which is:

function printreceipt(tax,subtotal,total)
{
subtotalElem=document.getElementById("total");
var taxElem=document.getElementById("tax");
productElem=document.getElementById("product-name");
alert("here are my products" + taxElem.innerHTML + subtotalElem.innerHTML);
}

如何将 JavaScript 变量发送到 Java 小程序?

How to send JavaScript variables to Java applet?

推荐答案

你的小程序应该有一个公共方法,例如 receiveData() :

Your applet should have a public method , for example receiveData() :

public void receiveData(String dataFromJS)
{
   //Do what you need with your data
}

假设您的网页中有类似内容:

Let's say you have something like that in your web page :

<applet id ="appletID" name="myApplet" ... ></applet>

在你的javascript中,你只需要像这样调用applet公共方法:

In your javascript you just have to call the applet public method like this :

var myApp = document.applets['myApplet'];
myApp.receiveData(taxElem.innerHTML + subtotalElem.innerHTML);

前面的示例将向小程序发送 taxElem 和 subtotalElem 内容.

The previous example will send the taxElem and subtotalElem content to the applet.

要将数据从 Applet 发送到 JS,您应该使用 JSObject 在你的小程序中

To send data from Applet to JS you sould use JSObject in your applet

这篇关于如何将 JavaScript 变量发送到 Java 小程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆