- <!DOCTYPE html>
- <html>
- <head>
- <title>Text Test</title>
- <meta charset="utf-8" />
- <style>
- *{margin: 0;padding: 0;}
- p{height: 300px;width:300px;border: 1px solid #0058D2;}
- b{cursor: pointer;}
- span{display: block;direction:rtl; unicode-bidi:bidi-override;}
- </style>
- </head>
- <body>
- <p id="p"></p>
- <b id="b">小明:</b>
- <input id="test" type="text" />
- <button id="btn">发送</button>
- <script>
- window.οnlοad=function(){
- var oP=document.getElementById('p');
- var oB=document.getElementById('b');
- var oTest=document.getElementById('test');
- var oBtn=document.getElementById('btn');
- oBtn.οnclick=function(){
- var oSpan=document.createElement('span');
- oP.appendChild(oSpan);
- if(oTest.value==''){
- return false;
- }
- oSpan.innerHTML=oSpan.innerHTML+oB.innerHTML+oTest.value;
- oTest.value='';
- if(oB.innerHTML=='我:'){
- oSpan.style.textAlign='right';
- oSpan.style.direction='rtl';
- oSpan.style.unicodeBidi='bidi-override';
- }else if(oB.innerHTML=='小明:'){
- oSpan.style.textAlign='left';
- oSpan.style.direction='ltr';
- oSpan.style.unicodeBidi='embed';
- }
- }
- oB.οnclick=function(){
- if(this.innerHTML=='我:'){
- this.innerHTML='小明:';
- }else{
- this.innerHTML='我:';
- }
- }
- }
- </script>
- </body>
- </html>
转载于:https://www.cnblogs.com/yjgbk/p/5890153.html