如何使用JavaScript变量设置applet的param标签值?

时间:2014-10-24 10:58:00

标签: javascript html deployment applet

这是我的外部javaScript名为myJs.js

function search(){
    var hint = document.getElementById("sChoice").value;
    var item = document.getElementById("sKey").value;
    document.getElementById("c").value=hint;
    document.getElementById("iK").value=item;
}

这是我的主页html

 <script src="myJs.js"></script>
    <form name="data" action="sResult.html" method="get">
    <label>Select your Method use to search</label><br>
    <select id="sChoice">
        <option value="book">By Book Name</option>
        <option value="author">By Author Name</option>
        <option value="subject">By Subject Name</option>
    </select>
    <input type="text" id="sKey"><button onClick="search()">Search</button></br></br>
</form>

此处此代码位于另一个名为&#34; sResult.html&#34;

的html doc上
<script src="myJs.js"></script>
<form name="data" action="sResult.html" method="get">
    <caption>
        <applet code="SearchResult.class">
            <param name="choice" id="c" value="&{hint};">
            <param name="itemKey" id="iK" value="&{item};">
        </applet>
    </caption>
</form>

我的问题是我无法在运行时通过JavaScript获取传递给param标记的值,我在用户"getPrameter("choice")""getParameter("itemKey")"接收{app} {app} }值。

1 个答案:

答案 0 :(得分:0)

HTML5中不支持

applet标记,因此我建议您使用对象标记。像:

HTML:

<object type="application/x-java-applet" height="400" width="644" >
<param name="code" value="sample.package.Sample.class">//class name including the package name where your applet main defined
<param name="archive" value="external libs">//path to external libs if any
<param name="param1" value="value1">
<param name="paramN" value="valueN">
Applet failed to run.  No Java plug-in was found.//if browser does not support java
</object>

Sample.java:

package sample.package;

public class Sample extends Applet{

@Override

public void init(){
String param1=getParameter("param1");
}

}

<强>更新

如果您使用JavaScript设置param value,那么您需要将JavaScript variables声明为全局:

<script>
var hint="";
function search(){
hint = document.getElementById("sChoice").value;
}
</script>

您需要将hint声明为全局,而search()内部函数只需更新它。您不需要设置参数值。从代码中删除这些行

document.getElementById("c").value=hint;
document.getElementById("iK").value=item;

完整的JavaScript应该是:

<script>

var hint="";
var item="";

function search(){
    hint = document.getElementById("sChoice").value;
    item = document.getElementById("sKey").value;
}

</script>