|
|
|
จะกดหนดให้ scroll bar ให้อยู่ข้างล่างในช่องแชทจะต้องใช้คำสั่งไหนหรอครับ |
|
|
|
|
|
|
|
var myDiv = document.getElementById('myDiv');
myDiv.scrollTop = myDiv.scrollHeight;
|
|
|
|
|
Date :
2015-04-08 13:33:04 |
By :
Chaidhanan |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
เอา code ใส่ตรงไหนครับ
|
|
|
|
|
Date :
2015-04-09 13:10:24 |
By :
Tachi |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5555 แล้วผมจะรู้ไหมเนี่ย โค๊ดก็ไม่มีมาให้ดู
มันเป็น javascript ครับ ก็ลอง apply เอาเองนะครับ
|
|
|
|
|
Date :
2015-04-09 13:15:23 |
By :
Chaidhanan |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ลองดูตัวนี้ครับ
Code
// focus //
var el = document.getElementById('mydiv');
el.tabIndex = 32456;
el.focus();
Ajax Chat Room (PHP+Text & ASP+Text)
|
|
|
|
|
Date :
2015-04-09 13:34:51 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
โค็ดครับ
Code (PHP)
<?php
session_start();
mysql_connect("localhost","root","1897298qw");
mysql_select_db("AccountsDB");
$strSQL = "SELECT * FROM member WHERE UserID = '".$_SESSION['UserID']."' ";
$objQuery = mysql_query($strSQL);
$objResult = mysql_fetch_array($objQuery);
if(isset($_POST['submit']))
{
$con = mysql_connect("localhost","root","1897298qw");
if (!$con){die('Could not connect: ' . mysql_error());}
if(!isset( $_POST['message']) || ($l=strlen($_POST['message'])) < 1 || $l>30)
{
$string = array('<div class="alert alert-error" align="center">ข้อความของคุณสั้นเกินไป หรือ ยาวเกินไป</div>');
}
else
{
mysql_select_db("AccountsDB", $con);
$message= $_POST['message'];
$sender= $objResult["Username"];
mysql_query("INSERT INTO message(message, sender)VALUES('$message', '$sender')");
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Simple Chat</title>
<script language="javascript" src="jquery-1.2.6.min.js"></script>
<script language="javascript" src="jquery.timers-1.0.0.js"></script>
<script type="text/javascript">
$(document).ready(function(){
var j = jQuery.noConflict();
j(document).ready(function()
{
j(".refresh").everyTime(1000,function(i){
j.ajax({
url: "refresh.php",
cache: false,
success: function(html){
j(".refresh").html(html);
}
})
})
});
j(document).ready(function() {
j('#post_button').click(function() {
$text = $('#post_text').val();
j.ajax({
type: "POST",
cache: true,
url: "save.php",
data: "text="+$text,
success: function(data) {
alert('data has been stored to database');
}
});
});
});
j('.refresh').css({color:"green"});
});
</script>
<style type="text/css">
.refresh {
border: 1px solid #3366FF;
border-left: 4px solid #3366FF;
color: green;
font-family: tahoma;
font-size: 12px;
height: 225px;
overflow: auto;
width: 265px;
padding:10px;
background-color:#FFFFFF;
float: left;
display: table-row-group;
}
.refresh-u {
border: 1px solid #3366FF;
border-left: 4px solid #3366FF;
color: green;
font-family: tahoma;
font-size: 12px;
height: 225px;
overflow: auto;
width: 100px;
padding:10px;
background-color:#FFFFFF;
margin-left: 5px;
}
#post_button{
border: 1px solid #3366FF;
background-color:#3366FF;
width: 100px;
color:#FFFFFF;
font-weight: bold;
margin-left: -105px; padding-top: 4px; padding-bottom: 4px;
cursor:pointer;
}
#textb{
border: 1px solid #3366FF;
border-left: 4px solid #3366FF;
width: 320px;
margin-top: 10px;
padding-top: 5px;
padding-bottom: 5px;
padding-left: 5px;
width: 320px;
}
#texta{
border: 1px solid #3366FF;
border-left: 4px solid #3366FF;
width: 220px;
margin-bottom: 10px;
padding:5px;
margin-top: 10px;
}
.p-s{
border-top: 1px solid #EEEEEE;
margin-top: 0px; margin-bottom: 5px; padding-top: 5px;
}
.span-s{
font-weight: bold;
color: #3B5998;
}
.online-list{
font-weight: bold;
color: #3B5998;
margin-top: 10px;
}
</style>
</head>
<body>
<form method="POST" name="" action="" autocomplete="off" wrap='off' rows="10">
<div class="refresh">
<?php
$con = mysql_connect("localhost","root","1897298qw");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("AccountsDB", $con);
$result = mysql_query("SELECT * FROM message ORDER BY id ASC");
while($row = mysql_fetch_array($result))
{
echo '<div class="p-s">'.'<div class="span-s">'.$row['sender'].'</div>'. ': ' . $row['message'].'</div>';
}
mysql_close($con);
?>
</div>
<div class="refresh-u">
<div class="online-list">Gust: 0</div>
<div class="online-list">Members: 0</div>
<div class="online-list">Admins: 1</div>
<p> </p>
</div>
<p>
<input name="sender" type="text" id="texta" value="ชื่อผู้ใช้งาน: <?php echo $objResult["Username"];?>" readonly="readonly" />
</p>
<p>
<input name="message" type="text" id="textb" />
<input name="submit" type="submit" value="ส่งข้อความ" id="post_button" />
</p>
<p><?php if(isset($_POST['submit']))
{
if(isset($string))
{
echo "{$string[0]}";
}
}
?></p>
</form>
</body>
</html>
|
|
|
|
|
Date :
2015-04-09 16:36:03 |
By :
Tachi |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
แล้วจะเลือกเอาแต่ข้อความล่าสุดมาลงให้ช่องแชทจะกำหนด row Mysql ยังไงครับ
|
ประวัติการแก้ไข 2015-04-09 17:05:13
|
|
|
|
Date :
2015-04-09 17:03:24 |
By :
Tachi |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|