如何在使用javascript加载页面时直接设置对象参数

how to set object param directly when page load with javascript?

本文关键字:设置 参数 对象 加载 javascript      更新时间:2023-09-26

我想直接从参数值读取NPAPi插件

这是我当前的JS和表单代码

<script>
var control = document.getElementById('embed');
</script>

<form name="formname">
<input type=button value="Inc name" onclick='embed.name="albert";'>
<input type=button value="Inc phone" onclick='embed.phone="123456";'>
</form>

这可以将embed.nameembed.phone传递到我的dll

如何在不使用表单或点击事件的情况下以相同的方式直接使用javascript设置参数:

<EMBED id="embed" TYPE="application/x-plugin" ALIGN=CENTER WIDTH=400 HEIGHT=300>
<param name="name" value="albert" />   
<param name="phone" value="123456" /> 
</EMBED>

您应该能够使用setAttribute创建名称-值对。

document.getElementById("embed").setAttribute("name", "albert");
document.getElementById("embed").setAttribute("phone", "123456");

然后,您可以稍后使用getAttribute访问这些值,尽管我不确定"embed"是否是元素id的保留字。