js代码
<script src="js/jquery.min.js"></script> <script>$("html").css("font-size", 20 * ($(window).width() / 640) + 'px');</script> <script> window.onload = function() { var arrIcon = ['images/1.jpg', 'images/2.jpg']; var num = 0; //控制头像改变 var iNow = -1; //用来累加改变左右浮动 var icon = $('#user_face_icon')[0].getElementsByTagName('img'); var btn = $('#btn')[0]; var text = $('#text'); var content = $('.content')[0]; var img = content.getElementsByTagName('img'); var span = content.getElementsByTagName('span'); var i = content.getElementsByTagName('i'); icon[0].onclick = function() { if (num == 0) { this.src = arrIcon[1]; num = 1; } else if (num == 1) { this.src = arrIcon[0]; num = 0; } } btn.onclick = function() { if (text.html() == '') { alert('不能发送空消息'); } else { content.innerHTML += '<li><img src="' + arrIcon[num] + '"><span>' + text.html() + '</span><i>已读</i></li>'; iNow++; if (num == 0) { img[iNow].className += 'imgright'; span[iNow].className += 'spanright'; i[iNow].className += 'iright' } else { img[iNow].className += 'imgleft'; span[iNow].className += 'spanleft'; i[iNow].className += 'ileft' } text.html(''); // 内容过多时,将滚动条放置到最底端 content.scrollTop = content.scrollHeight; } } } </script>