1 回答
TA贡献1850条经验 获得超11个赞
var p = document.createElement('p');
var message = document.querySelector('#messages');
var button = document.querySelector('#typeb');
button.addEventListener('click', function() {
p = document.createElement('p');
p.setAttribute('id', 'user');
var txt = document.createTextNode('This is a message sent.');
p.appendChild(txt);
message.appendChild(p);
reply();
});
function reply() {
p = document.createElement('p');
p.setAttribute('id', 'sent');
var txt = document.createTextNode('This is a message sent. jwejfhwewfwwef \n Hello Priyal');
p.appendChild(txt);
message.appendChild(p);
}
#box {
position: relative;
text-align: center;
}
#typer {
position: fixed;
bottom:0;
}
#typeb {
position: fixed;
bottom:0;
}
#user {
min-width: 150px;
min-height: 40px;
float: right;
display: block;
clear: both;
text-align: right;
background-color: aqua;
border: 1px solid aqua;
border-bottom-right-radius: 0px;
border-radius: 30px 0px 30px 30px;
}
#sent {
min-width: 150px;
min-height: 40px;
float: left;
display: block;
clear: both;
background-color: grey;
border: 1px solid grey;
border-bottom-left-radius: 0px;
border-radius: 0px 30px 30px 30px;
}
<div id="box">
<div id="messages">
</div>
<input type="text" id="typer">
<button id="typeb">Say it</button>
</div>
添加回答
举报