如何使用jquery更改html标记中的值

时间:2011-08-29 11:24:40

标签: javascript jquery

我想根据下拉列表中的值更改applet标记的param值。 我是jquery的新手。有人告诉我如何使用jquery做到这一点。

我的小程序代码:

<applet id="decisiontree" code="com.vaannila.utility.dynamicTreeApplet.class" archive="./appletjars/dynamictree.jar, ./appletjars/prefuse.jar" width ="1000" height="500" >
 <param name="dieasenmae" value="Malaria"/>
 </applet>

我的dropdownc代码:

<html:select name="AuthoringForm" property="disease_name" size="1" onchange="javascript:showSelected(this.value)">
<option>Malaria</option>
<option>High Fever</option>
<option>Cholera</option>
</html:select></p>

的javascript:

function showSelected(value){
alert("the value given from dropdown is "+value);   
$("#decisiontree param[name='dieasenmae']").val(value); 
}

3 个答案:

答案 0 :(得分:3)

只需使用:

var myNewValue = 'my new value';

$("#decisiontree param[name='dieasenmae']").val( myNewValue );

直播example on JSBin

选择器说明:

$("#decisiontree param[name='dieasenmae']")
        ^          ^    ^        ^
        1          2    3        4
  • 1 - &gt;在ID decisiontree
  • 2 - &gt;找到param
  • 类型的所有元素
  • 3 - &gt;具有属性name
  • 4 - &gt;并且该属性值必须为dieasenmae

既然您知道如何更改值,那并不意味着它会起作用!因为你需要理解并看到<applet>将如何工作,正常情况下,它会在开始时加载所有值,无论你在DOM中做什么,Applet都可以忽略它......应该有一个refresh applet,为此,最简单的方法是跟进这个问题:

Is there a way to reload/refresh a java applet from within the applet itself?

答案 1 :(得分:0)

$('param').attr('value','your-value');

$('param').val('your-value');

确保在dom准备就绪时启动它或使用document.ready

答案 2 :(得分:0)

    $(document).ready(function()
    {
       $("#decisiontree param").val("newValue");
       // or
      $("#decisiontree param").attr("value","newValue");
});