87,907
社区成员
发帖
与我相关
我的任务
分享
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="http://apps.bdimg.com/libs/jquery/1.6.4/jquery.min.js"></script>
<style type="text/css">
.container {
background-color: #FFFFFF;
width: 600px;
height: 500px;
}
.tanmu {
width: 600px;
height: 500px;
background-color: #060606;
}
#textstyle {
font-size: 11px;
color: red;
}
</style>
<script type="text/javascript">
function tanmu() {
var text = document.getElementById("text");
var tanmu = document.getElementById("tanmu");
var textinnelHTML = "<font id=\"textstyle\">" + text.value + "</font>";
alert(textinnelHTML);
var x = tanmu.offsetWidth;
var y = Math.round(Math.random() * tanmu.offsetHeight);
tanmu.innerHTML = textinnelHTML;
var textobj = document.getElementById("textstyle");
alert(textobj.style.left);
textobj.style.left = x + "px";
textobj.style.top = y + "px";
}
</script>
</head>
<body>
<div class="container">
<div class="tanmu" id="tanmu"></div>
</div>
<input type="text" value="这是弹幕" id="text" />
<input type="button" value="发送" onclick="tanmu();" />
</body>
</html>
var textobj = document.getElementById("textstyle");
textobj.style.left = x + "px";
textobj.style.top = y + "px";
alert(textobj.style.left);
都没设值呢怎么能打印出来呢 ? 如果还没有,那加个绝对定位,如果还没有,看下哪里有!impoortant设置了样式