我试图让这个盒子在150px处保持一个宽度,但是我如何得到重复的文本,将文本返回到下一行而不是展开div。
<div id="page" style="position:absolute; float:right; top:500px; right:0px; background-color:#F5F5F5; color: #F6221D; font-size:12px; width:150;">
<h2>ShoutOut</h2>
<form method="post" action="shout.php">
<strong>Message:</strong>
<input type="text" id="message" name="message" class="message" /><input type="submit" id="submit" value="Submit" />
</form>
<div id="shout" style="padding:0 10px 0; width:150; height:170px;; overflow-y:auto;">
</div>
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
//populating shoutbox the first time
refresh_shoutbox();
// recurring refresh every 15 seconds
setInterval("refresh_shoutbox()", 15000);
$("#submit").click(function() {
// getting the values that user typed
var name = $("#name").val();
var message = $("#message").val();
// forming the queryString
var data = 'name='+ name +'&message='+ message;
// ajax call
$.ajax({
type: "POST",
url: "shout.php",
data: data,
success: function(html){ // this happen after we get result
$("#shout").slideToggle(500, function(){
$(this).html(html).slideToggle(500);
$("#message").val("");
});
}
});
return false;
});
});
function refresh_shoutbox() {
var data = 'refresh=1';
$.ajax({
type: "POST",
url: "shout.php",
data: data,
success: function(html){ // this happen after we get result
$("#shout").html(html);
}
});
}
答案 0 :(得分:2)
CSS中存在错误:
width:150;
应该是:
width:150px;
答案 1 :(得分:1)
尝试将此样式添加到DIV:
word-wrap:break-word;