In my code I have this:
<textarea id="screen" cols="40" rows="20" readonly> </textarea>
which displays the data in the screen
id, obviously.
But when I change it to:
<span id="screen"></span>
or
<div id="screen"></div>
it shows nothing.
Go easy on me i'm a rookie.
this is in my script tag in the head section:
function update()
{
$.post("chat_new_serv.php", {}, function(data){ $("#screen").val(data);});
setTimeout('update()', 3000);
}
$(document).ready(
function()
{
update();
$("#button").click(
function()
{
$.post("chat_new_serv.php",
{ message: $("#message").val()},
function(data){
$("#screen").val(data);
$("#message").val("");
}
);
}
);
});
The new_chat_serv page just outputs the chat text from the database.
val()
will only get/set the contents of input elements ( TEXTAREA
included). Use html()
or text()
to get/set the contents of other HTML tags.
From your code:
$("#screen").val(data);
Would become:
$("#screen").html(data);
对于<textarea>
您可以使用.val()
,但是对于<div>
和<span>
您想要使用.html()
或.text()
。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.