日期:2014-05-16  浏览次数:20363 次

JAVASCRIPT对象问题
练习用的代码,请先看代码:
<BODY>
    <script   type= "text/javascript "   language= "javascript ">
    function   mouseOverFunction(e)
    {
if(window.event.shiftKey&&window.event.ctrl)
{
document.form1.textbox.value= "shif   and   ctrl   keys   down   and   mous   over   at   : "+window.event.x+ " ' "+window.event.y
return
                  }
    }
</script>

<center>
<form   name= "form1 "   action= "action ">
<h1> use   the   mouse   in   javascript </h1>
<br/>
clickthemouse(hold   shift   ctrl   alt)
<br/>
<a   href= "mouse.htm "   name= "mouselink "
onmouseover= "mouseOverFunction() "
>
move   the   mouse   please
</a>
<br/>
<br/>
<input   type= "text "   name= "textbox "   size= "60 "/>
</form>
</center>
   
  </BODY>
我只复制了BODY部分,运行时提示提示onmouseover= "mouseOverFunction() "这一行找不到对象,请大家帮忙看看!另外请大家讲一下JS对象的问题,谢谢啦!

------解决方案--------------------
onmouseover= "mouseOverFunction() "
是找不到这个对象
上面只有 mouseOverFunction(e) 这个对象

一个是有参数的,一个是没参数的,虽然看起来差不多,可是电脑是很严格的

JS的对象就很多了,要说对象其实所有语言都差不多的原理
------解决方案--------------------
document.form1.textbox,不要这样用
有时候去不到的
还是好好的getElementById或者TagName,参数是没有关系的
一步步试,可以找出错误来的

------解决方案--------------------
if(window.event.shiftKey&&window.event.ctrl)这里错了,因该是if(window.event.shiftKey && window.event.ctrl)
------解决方案--------------------
onmouseover= "mouseOverFunction() "
是找不到这个对象
上面只有 mouseOverFunction(e) 这个对象

一个是有参数的,一个是没参数的,虽然看起来差不多,可是电脑是很严格的

JS的对象就很多了,要说对象其实所有语言都差不多的原理
----------------------------------------------------
乱讲
mouseOverFunction(e)的e有时候可以捕捉到事件对象,只是楼主的代码没用的
-----------------------------------------------------
if(window.event.shiftKey&&window.event.ctrl)这里错了,因该是if(window.event.shiftKey && window.event.ctrl)
-------------------------------------------------------
没话讲了,5个裤衩也不知道哪里捡来的
-----------------------------------------------------

楼主的问题其实是因为没有event.ctrl
所以这段函数应该是
function mouseOverFunction(e)
{
e = e || window.event;
if(window.event.shiftKey&&window.event.ctrlKey)
{
document.form1.textbox.value= "shif and ctrl keys down and mous over at : "+e.x+ " ' "+e.y;
return;
}
}