How to read the param value from the object tag using javascript

半城伤御伤魂 提交于 2020-01-04 06:07:43

问题


Is it possible to read the playerID value using JavaScript?

<object id="myid" class="newclass">
  <param name="bgcolor" value="#FFFFFF" />
  <param name="width" value="345" />
  <param name="height" value="216" />
  <param name="playerID" value="1234" />
  <param name="playerKey" value="AFASS" />
  <param name="isVid" value="true" />
  <param name="isUI" value="true" />
</object>

回答1:


Or, you can try the following statement. It will return all the play IDs on the page, if you have multiple.

var playerIDs = document.getElementsByName('playerID');

playerIDs will be an array. If you only have one playerID on the page, you can just say playerIDs[0]




回答2:


try this:

var obj = document.getElementById('myId');
var value = '';
for(var param in obj.childNodes){
   if (obj.childNodes[param].getAttribute('name') == 'playerID'){
      value = obj.childNodes[param].getAttribute('value');
      break;
   }
}


来源:https://stackoverflow.com/questions/9067532/how-to-read-the-param-value-from-the-object-tag-using-javascript

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!