注册 登录
编程论坛 JavaScript论坛

请问这样用对吗

yaopeng0418 发布于 2010-09-19 17:33, 470 次点击
    $("#voice>div").each(function(i){
this.onmouseover="this.innerHTML='<embed src='bird.mp3' style='display:none' loop='1' autostart=true>'+'<img src='song.gif' name='bird.mp3' width='16' height='16'/>'+this.innerHTML";
 });
3 回复
#2
pigzee2010-09-21 10:34
用appendto 或者append更清楚明了吧。我也不是很懂,共同学习!
#3
pigzee2010-09-21 10:58
程序代码:
html:
<div id="test">
    <div>first</div>
    <div>second</div>
</div>

js:
<script>
    $(function(){
        $('#test >div').mouseover(function(){
            alert(this.innerHTML);
            this.innerHTML="<embed src='bird.mp3' style='display:none' loop='1' autostart=true>"
                            +"<img src='song.gif' name='bird.mp3' width='16' height='16'/>"
                            +this.innerHTML;
            alert(this.innerHTML);            
        });
    //    "this.innerHTML='<embed src='bird.mp3' style='display:none' loop='1' autostart=true>'+'<img src='song.gif' name='bird.mp3' width='16' height='16'/>'+this.innerHTML";
    });
</script>
#4
gulimeksoft2010-09-21 17:17
楼上的可以,你的可以加个function,不过显得多余
   $("#voice>div").each(function(i){
this.onmouseover=function(){
this.innerHTML='<embed src='bird.mp3' style='display:none' loop='1' autostart=true>'+'<img src='song.gif' name='bird.mp3' width='16' height='16'/>'+this.innerHTML";}
});

innerHTML可以用$(this).html("str")还可以用实现
1