日期:2014-05-18  浏览次数:20441 次

急!急!急!VS2008中的按钮问题
在WebForm中按钮默认设置回车键的代码是:
<script type=text/javascript>
function Enter()
{
  if(event.keycode==13)
  {
  event.returnValue=false;
  event.cancel=true;
  document.getElementById("ButtonID").onclick();
  }

}
</script>

Web窗体里这样绑定<body onkeydown="Enter()">
Web用户控件里怎么绑定,还是不是这么写的?

------解决方案--------------------
webControl.attributes.add("onkeydown","enter()")
------解决方案--------------------
探讨
webControl.attributes.add("onkeydown","enter()")

------解决方案--------------------
webControl.attributes.add("onkeydown","enter()");
------解决方案--------------------
探讨
webControl.attributes.add("onkeydown","enter()")

------解决方案--------------------
JScript code

<script type="text/javascript">
function Enter()
{
  if(event.keyCode==13)//keyCode这个C是大写的
    {
      document.getElementById("ButtonID").click();//是click不是onclick
      return false;
    }
return true;
}
</script>

------解决方案--------------------
只要在 document.onKeyDown 中处理下就好了。

HTML code
<script type=text/javascript> 
function Enter() 
{ 
  if(event.keycode==13) 
    { 
      event.returnValue=false; 
      event.cancel=true; 
      document.getElementById("ButtonID").onclick(); 
    } 

} 
document.onKeyDown = Enter();
</script>