Applet可以操作HTML的元素吗?
问题点数:50、回复次数:5Top
1 楼bootcool(bootcool)回复于 2001-04-27 20:29:00 得分 0
能说得清楚些吗?
要实现什么样的功能?
Top
2 楼mikehofly(小川)回复于 2001-04-27 20:31:00 得分 0
当我按下Applet里面的一个按钮时,
其所在的网页或者同一框架的网页的某写元素会发生响应变化.Top
3 楼masterz(www.fruitfruit.com)回复于 2001-04-27 20:46:00 得分 50
在applet中调用jscript:
import netscape.javascript.*;
JSObject win = (JSObject) JSObject.getWindow(this);
win.eval("funcName();");
//here you can call funcName() function from within applet.
Top
4 楼bootcool(bootcool)回复于 2001-04-27 21:25:00 得分 0
Hi,
You may have a javascript function execute an applet's method and retrieving the method's result.
If you have an appled called MyApplet with a public method called myMethod(), you might do this the following way:
<HTML>
<HEAD>
<TITLE>Example Javascript/Applet</TITLE>
<SCRIPT language="javascript">
function execute() {
result = myapp.myMethod();
alert ("Method myMethod returned: "+result);
}
</SCRIPT>
</HEAD>
<BODY>
<APPLET code="MyApplet" width="100" height="100" name="myapp">
<FORM>
<INPUT type="BUTTON" value="Execute Method" onclick="execute()">
</FORM>
</BODY>
</HTML>
Note that the key to that is the "name" property on the <APPLET>
tag. This name is used by javascript to call the applet.
I hope this may help you. Regards,
Top
5 楼bootcool(bootcool)回复于 2001-04-27 21:53:00 得分 0
//希望能有用
//纠正一下,html代码应写为:
<HTML>
<HEAD>
<TITLE>Example Javascript/Applet</TITLE>
<SCRIPT language="javascript">
<!--
function execute() {
result = myapp.myMethod();
alert ("Method myMethod returned: "+result);
}
//-->
</SCRIPT>
</HEAD>
<BODY>
<FORM>
<INPUT type="BUTTON" value="Execute Method" onclick="execute()">
</FORM>
<APPLET code="MyApp.class" width="100" height="100" name="myapp">
</BODY>
</HTML>
//这是测试程序
import java.awt.*;
import java.applet.*;
public class MyApp extends Applet{
Graphics g;
public void init(){
g = getGraphics();
}
public void myMethod(){
g.drawString("Hello World", 20, 20);
}
}
Top




