请问一个鼠标跟随的问题!

ligman 2003-10-18 10:02:31
<script languae=javascript>
function gensui()
{
var x=event.x;
var y=event.y;
document.all.layer1.style.left=x;
document.all.layer1.style.top=y;
}
document.onmousemove=gensui;
</script>
<div id="layer1" style="position:absolute;left:100;top:100">
<font>hello</font>
</div>
问题如下:
1. document.onmousemove=gensui;中gensui后面为什么不要"()"?
2.还是这句,前面为什么要加一个document.?为什么不能直接写onmousemove=……?
...全文
33 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
ligman 2003-10-18
  • 打赏
  • 举报
回复
顺便问一下层中的颜色又怎么设置呢?
<div id=layer1 style="position:absolute;color=yellow">
颜色
</div>
然后怎么在JAVASCRIPT里改变它的值呢?
document.all.layer1.style.color=red(错!)
document.all.layer1.style.fontColor=red(还是错!)
??????
ligman 2003-10-18
  • 打赏
  • 举报
回复
请问怎样隐藏鼠标?
xuzuning 2003-10-18
  • 打赏
  • 举报
回复
想法很有趣,不过你写错了
样式表中的属性名在脚本中的书写格式有变化,主要是避免“-”的歧义
“-”后面的字母大写“-”不要
css style="font-size:100"
js style.fontSize = x;

<script language=javascript>
function bian()
{
var x=event.x;
document.all.layer1.style.fontSize=x;
}
document.onmousemove=bian;
</script>
<div id=layer1 style="position:absolute;font-size:100;color:yellow">

</div>

另外
1. document.onmousemove=gensui;中gensui后面为什么不要"()"?
因为这是设定该事件的处理程序,有"()"就要执行了

2.还是这句,前面为什么要加一个document.?为什么不能直接写onmousemove=……?
需要知道是哪个(类)对象的事件
ligman 2003-10-18
  • 打赏
  • 举报
回复
有另外一个脚本,请帮忙解释一下:
<script language=javascript>
function bian()
{
var x=event.x;
document.all.layer1.style.font-size=x;
}
document.onmousemove=bian;
</script>
<div id=layer1 style="position:absolute;font-size=100;color:yellow">

</div>
为什么这个“变”字不能随着鼠标的移动而变化大小?
xishanlang2001 2003-10-18
  • 打赏
  • 举报
回复
1.()在脚 本里要求不是很严格.
2.如果要那么写.可以写成这样:
<html><body onmousemove=gensui()>
<script languae=javascript>
function gensui()
{
var x=event.x;
var y=event.y;
document.all.layer1.style.left=x;
document.all.layer1.style.top=y;
}
//document.onmousemove=gensui;
</script>
<div id="layer1" style="position:absolute;left:100;top:100">
<font>hello</font>
</div>
</body>
</html>

87,902

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧