我正在尝试使用上述插件,但只能在带有静态文本的 div 中使用。
例如这行得通:
<div id = "header" name = "header" class = "header" >
<?php
echo "Hi :)
?>
</div>
这不会改变任何东西:
<div id='chatArea' name='chatArea' class='chatArea'>
<script>chatRefresh();</script>
</div>
chatRefresh() 包含:
function chatRefresh(){$("#chatArea").load("doShowMessage.php");}
setInterval('chatRefresh()', 5000);
emoticonizing() 包含:
function emoticonizing()
{
$(document).ready(function() {
$('#header').emoticonize({
});
$('#chatArea').emoticonize({
});
});
}
如果我在 chatArea 内调用 emoticonizing(),它会挂起;如果我在外部调用它,它会运行但无法正常工作。 此外,如果我在 div chatArea 之外调用 chatRefresh(),它会在 5 秒后加载,而不是立即加载并每 5 秒刷新一次。 (顺便说一句,我正在研究如何使用 jQuery 为该函数实现某种长轮询)。
整个 html View 是:
<?php
if (!isset($_SESSION)) {
session_start();
}
include 'header.php';
//include './functions/doLogout.php';
?>
<script>chatRefresh();</script> <-- Loads after 5secs in here
<script>emoticonizing();</script> <-- runs but not working properly
<div id='wrapper' name='wrapper' >
<div name='logout' class=''>
<form id='logoutForm' action='./functions/doLogout.php' method='post'>
<input type='submit' name='logout' id='logout'/><br/>
</form>
</div>
<div id='chatBody' name='chatBody' class='chatBody'>
:D
<div id='chatArea' name='chatArea' class='chatArea'>
<script>chatRefresh();</script> <--Loads instanly here
<script>emoticonizing();</script> <-- works sometimes but hangs 99% of the time
</div>
</div>
<div id='onlineUsersDiv' name='onlineUsersDiv' class='chatOnUser' >
Online Users:
<div id='onlineUsers'>
<script>userRefresh();</script>
</div>
</div>
<div name='chatBox' class='chatBox'>
<form id="chatForm" method="post" action="doPostMessage.php"> <br/>
<input type='text' name='chatText' id='chatText' autocomplete='off' /><br/>
<input type='submit' name='sendButton' value='Send' /> <br/>
</form>
</div>
</div>
<?php
include 'footer.php';
?>
我对 javascript 和这一切还很陌生,所以欢迎发表评论。
最佳答案
我相信您需要将表情插件重新绑定(bind)到新生成的内容。每次内容更改时,调用“表情化”内容的功能。类似的东西。
function chatRefresh(){
$("#chatArea").load("doShowMessage.php")
emoticonizing();
;}
关于javascript - jQuery CSS 表情崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20805122/