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

关于javascript的小问题
<asp:textbox   id= "txtGoodsName "   runat= "server "> </asp:textbox>
1.当页面打开是,txtGoodsName自动获得焦点
2.当txtGoodsName中输入数据回车时,执行Save()事件
请问怎么写代码

------解决方案--------------------
<asp:textbox id= "txtGoodsName " runat= "server " onClientClick= "return IsEnterPressed() "> </asp:textbox>
<script>
document.all.item( "txtGoodsName ").focus();
function IsEnterPressed()
{
//写出判断是否为空
//判断是否回车
if( window.event.keyCode == 13 )
{
Save();//保存函数
return false;
}
}
</script>
------解决方案--------------------
window.onload=function()
{
var txt=document.all.txtGoodsName;
txt.focus();
}
这样就可以了
------解决方案--------------------
Save()事件 是服务器短事件吗