<script language="javascript">
function play_click(mp3snd){    var div = document.getElementById('div1');
 
if ( navigator.userAgent.toLowerCase().indexOf( "msie" ) != -1 ) {
var _s = document.getElementById('snd'); 
_s.src = mp3snd; 
  
}else if ( navigator.userAgent.toLowerCase().indexOf( "firefox" ) != -1 ) {
div.innerHTML='<object data="'+mp3snd+'" type="application/x-mplayer2" width="0" height="0">';
div.innerHTML='<param name="filename" value="'+mp3snd+'">';
div.innerHTML='<param name="autostart" value="1">';
div.innerHTML='<param name="playcount" value="infinite">';
div.innerHTML='</object>';
}
else {
div.innerHTML='<audio src="'+mp3snd+'" autoplay="autoplay" >';
div.innerHTML='<object data="'+mp3snd+'" type="application/x-mplayer2" width="0" height="0">';
div.innerHTML='<param name="filename" value="'+mp3snd+'">';
div.innerHTML='<param name="autostart" value="1">';
div.innerHTML='<embed height="2" width="2" src="'+mp3snd+'" pluginspage="http://www.apple.com/quicktime/download/" type="video/quicktime" controller="false" controls="false" autoplay="true" autostart="true" loop="false" bgcolor="#'+bkcolor+'"><br>';
div.innerHTML='</embed></object>';
div.innerHTML='</audio>';
}}
</script> <li><a href='/about/' onmouseover="play_click('/star/sound2.mp3');" >关于我们</a> </li>

<li><a href='/daxinghuodong/' onmouseover="play_click('/star/sound2.mp3');" >大型活动</a> </li>

 <li><a href='/yirenziyuan/' onmouseover="play_click('/star/sound2.mp3');" >明星资源</a> </li>
   这是鼠标悬停栏目之后,有一个背景声音, 而且是判断浏览器,然后不同的浏览器给用不同的程序给声音,IE下的可以了,但是火狐和谷歌浏览器,出现以下问题: 一,现在这样写的话,没有声音。 二,而如果要是我给body一个id 然后div.innerHTML=div.innerHTML+ ''这样写的话,,是有声音,但是,页面就跟刷新了一下似的。 三,如果把div.innerHTML还成document.write('.....')这样写,就会把页面的内容清空了~ 然后声音。 我想要的效果是,鼠标放上有声音,而且,页面不刷新~~  大侠们支个招~ 感激不尽啊~(ps:http://tech.cncms.com/sheji/js/96660.html 这是我获得代码的地址) 感激不尽啊~~javascriptfirefox浏览器

解决方案 »

  1.   

    LZ先用个字符串把HTML拼接起来,你那样写相当于div.innerHTML='</audio>',前面的都覆盖掉了;var html = '<audio src="'+mp3snd+'" autoplay="autoplay" >';
    html+='<object data="'+mp3snd+'" type="application/x-mplayer2" width="0" height="0">';
    html+='<param name="filename" value="'+mp3snd+'">';
    html+='<param name="autostart" value="1">';
    html+='<embed height="2" width="2" src="'+mp3snd+'" pluginspage="http://www.apple.com/quicktime/download/" type="video/quicktime" controller="false" controls="false" autoplay="true" autostart="true" loop="false" bgcolor="#'+bkcolor+'"><br>';
    html+='</embed></object>';
    html+='</audio>';
    div.innerHTML = html;document.write直接输出在浏览器
    innerHTML就是获取或设置指定DOM元素的内容,就是<div id="dddd"></div>之间的东西。document.getElementById('dddd').innerHTML = '<span>asfsdfasf</span>';
    结果就是
    <div id="dddd"><span>asfsdfasf</span></div>
      

  2.   

    首先  变量命名  尽量别用 div。
    1.要理解  赋值=号  跟 +=的区别呀。你以前的写法 就是 给 div赋了n次值,当然只能去最后一次的结果啦。可以alert一下试试看。
    2.document.write要看执行的位置。如果是在脚本前端的话,他会在当前位置执行,反之,关掉原来的页面会打开新页面。