[英]How to display the current time in right side corner of Text Area and mesage Text in left corner?
In my Customer side chat application jsp page , I have a text area that displays the messages from the Agent side and also displays the message from the customer . 在我的客户方聊天应用程序jsp页面中,我有一个文本区域,它显示来自代理方的消息,也显示来自客户的消息。
That works fine.My javaScript code is, 很好用。我的javaScript代码是,
function sendMessage(){
message =trim( document.getElementById("message").value);
document.getElementById("message").value = "";
if(message != null && message !="null" && message !=""){
try
{
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
var checkMsg = trim(xmlhttp.responseText.toString());
textarea = document.getElementById('textarea');
if(checkMsg != "null" && checkMsg != null && trim(checkMsg).length != 0) {
if(trim(textarea.value) == ""){
textarea.value = message = checkMsg;
textarea.scrollTop = textarea.scrollHeight;
}
else{
textarea.value += "\n"+checkMsg;
textarea.scrollTop = textarea.scrollHeight;
}
}
}
};
xmlhttp.open("POST", "SendMessageAction",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("charset","UTF-8");
xmlhttp.send("sessionId="+encodeURIComponent(sessionId)+"&userId="+encodeURIComponent(userId)+"&securekey="+encodeURIComponent(secureKey)+"&message="+encodeURIComponent(message)+"&sid="+Math.random());
}
catch(err)
{
alert(err.description);
}
}
}
In that I need to include the current time with the every messages appending in the text area at the right side corner of text area. 为此,我需要将当前时间包括在内,并将每条消息都附加在文本区域右上角的文本区域中。
I can append the current time with messages but I need to append it in right side corner of textarea with every messages? 我可以在当前时间后面加上消息,但是我需要在每条消息的文本区域的右上角加上它吗?
How can I do this.Please give some ideas or some code. 我该怎么办。请提供一些想法或代码。
Here is a function that displays current date/time: 这是一个显示当前日期/时间的函数:
If you want, you can extract just the time lines for time only. 如果需要,您可以仅提取时间线以获取时间。
function update(){
time = new Date();
year = (time.getFullYear());
month = (time.getMonth() + 1);
date = time.getDate();
hours = time.getHours();
mins = time.getMinutes();
secs = time.getSeconds();
if(mins.length<2){mins = "0"+secs}
if(secs.length<2){secs = "0"+secs}
if(month.length<2){month = "0"+secs}
if(date.length<2){date = "0"+secs}
// Config Starts
if(hours>12){hours=hours-12}else{hours}
format = year+"-"+month+"-"+date+" @ "+hours+":"+mins+":"+secs;
document.form1.box1.value = format;
// Config Ends
}
setInterval("update()",1000);
To display the results use: 要显示结果,请使用:
<script>
#right
{
float: right;
}
</script>
<div id="right">
<p>Current Date/Time is: <INPUT name="box1" type="text" size="20"></p>
</div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.