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!');
});
});
效果: