简体   繁体   English

HTML按钮onClick无法启动Applet

[英]HTML button onClick not launching Applet

I have an Applet program, which works fine in Eclipse. 我有一个Applet程序,可以在Eclipse中正常工作。 I want to load this applet when I click on a button action from a html code. 我想从html代码中单击按钮操作时加载此applet。 I have kept the html file in the same path where I have this applet class. 我将html文件保留在具有该applet类的相同路径中。 I am just testing now, so haven't hosted this html file in server, before that I want to test this is working. 我现在正在测试,因此尚未在服务器中托管此html文件,然后再测试是否可以正常工作。

I searched forums and trying like below, but I couldn't get it working as expected. 我搜索了论坛并尝试如下所示,但无法按预期运行。 Applet is not launching on click button event. Applet不会在单击按钮事件时启动。 I am missing something, could someone guide me to make this working? 我缺少了什么,有人可以指导我使它正常工作吗?

<HTML>
<HEAD>
    <TITLE> Welcome on board! </TITLE>
    <script>
        function loadApplet()
        {
            var appletbox=document.getElementById('MyApplet.class');

        }
    </script>
</HEAD>
<BODY>
    <p>Click here for new Applet session!</p>
    <button onclick="loadApplet">Click here</button>

</BODY>

I think this will work 我认为这会起作用

<HTML>
<HEAD>
    <TITLE> Welcome on board! </TITLE>
    <script type="text/javascript">
        function loadApplet()
        {
        alert("Load Applet");
        document.write("<applet code='MyApplet' height='300' width='300'></applet>");
        }
    </script>
</HEAD>
<BODY>
    <p>Click here for new Applet session!</p>
    <button onclick="loadApplet();">Click here</button>

</BODY>
</HTML>

I have tested on my machine and it is working 我已经在机器上测试过,并且可以正常工作

Try to add () for your function here, so you can use: 尝试在此处为您的函数添加() ,因此您可以使用:

<button onclick="loadApplet()">Click here</button>

instead of: 代替:

<button onclick="loadApplet">Click here</button>

You forgot to add brackets 你忘了加括号

Try this: 尝试这个:

 <button onclick="loadApplet()">Click here</button>

You are including your applet in wrong way. 您以错误的方式包含小程序。 Check my answer on other question. 检查对其他问题的回答。 You should use <applet> , <object> or <embed> tag to include applet on your page. 您应该使用<applet><object><embed>标记在页面上包括applet。 This starts applet automatically, but when you use my method you can append applet to page clicking the button. 这会自动启动applet,但是当您使用我的方法时 ,可以将applet附加到单击按钮的页面上。 In function loadApplet use code similar to my code. 在函数loadApplet使用与我的代码相似的代码。

On your page there is no element with id MyApplet.class , so you can't get this element by id. 您的页面上没有id为MyApplet.class元素,因此您不能通过id获得此元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM