您的位置:首页 > Web前端 > JQuery

jquery之div的text() 方法,无参返回值,有参设置值

2013-12-10 11:00 375 查看
1

HTML Code

 

                                           

<divid="clickMe">
   Click here and watch the text change!
</div>

                               

                           

CSS Code

 

                                           

div#clickMe {
   width: 300px;
   height: 100px;
   margin: 10px;
   background-color:
green;
   color: white;
   border: 1px solid black;
}

                               

                           

JavaScript Code

 

                                           

$(document).ready(function(){
   //e is the event variable, can prevent the default behavior
   //of the event or stop it from propogating up to the element's
   //parent elements
   $('div#clickMe').click(function(e){
       var oldText
=
$(this).text();
       $(this).text(oldText
+'Click added some text!');
   });

});

效果:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: