[英]How to display the current time in right side corner of Text Area and mesage Text in left corner?
在我的客戶方聊天應用程序jsp頁面中,我有一個文本區域,它顯示來自代理方的消息,也顯示來自客戶的消息。
很好用。我的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);
}
}
}
為此,我需要將當前時間包括在內,並將每條消息都附加在文本區域右上角的文本區域中。
我可以在當前時間后面加上消息,但是我需要在每條消息的文本區域的右上角加上它嗎?
我該怎么辦。請提供一些想法或代碼。
這是一個顯示當前日期/時間的函數:
如果需要,您可以僅提取時間線以獲取時間。
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);
要顯示結果,請使用:
<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.