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

查看:120
本文介绍了如何发送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的public方法是这样的:

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

在previous例如将发送taxElem和subtotalElem内容的小程序。

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

要从Applet的数据发送到您JS前人的精力使用的 JSObject 在你的applet

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

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

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