日期:2014-05-16  浏览次数:20395 次

getElementById问题 急急
<HTML>
<HEAD>
....
<script   language= "javascript ">
  document.getElementById( 'Player ').URL= 'C:\\下载文件\\音乐\\不孤单.mp3 ';
</script>
</HEAD>

<body>
<form   id= "Form1 "   method= "post "   runat= "server ">
<table   id= "tableRealTime ">
<tr>
<td> <ajax:AjaxPanel   id= "AjaxPanelRealTime "   runat= "server ">
</ajax:AjaxPanel>
</td>
<td   align= "right ">
<OBJECT   id= "Player "   classid= "CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6 "   VIEWASTEXT> ..... </OBJECT> </td> </tr> </table>


为什么ocument.getElementById( 'Player ').URL总是提示说为空或没有实例呢?

半天了没搞定   靠大家了

------解决方案--------------------
<script language= "javascript ">
document.getElementById( 'Player ').URL= 'C:\\下载文件\\音乐\\不孤单.mp3 ';
</script>
放得太靠前了 你的object还没创建好
你把上面那句放到最后面 或者
<script language= "javascript ">
function window.onload()
{
document.getElementById( 'Player ').URL= 'C:\\下载文件\\音乐\\不孤单.mp3 ';
}
</script>
------解决方案--------------------
<script> </script> 内的语句先被执行
------解决方案--------------------
表单还没执行,就先执行当然就为空了
....
<script language= "javascript ">
function fun_onload()
{document.getElementById( 'Player ').URL= 'C:\\下载文件\\音乐\\不孤单.mp3 ';}
</script>
</HEAD>

<body onload= "fun_onload() ">
....