在asp.net的textbox控件中敲回车为什么会返回到首页?
我做好的aspx网页用IIS运行后,焦点在文本框(文本框使用asp.net的标准控件textbox控件做的)时,按回车键返回到了首页,为什么?怎么解决?最好是按回车时能够...
我做好的aspx网页用IIS运行后,焦点在文本框(文本框使用asp.net的标准控件textbox控件做的)时,按回车键返回到了首页,为什么?怎么解决?最好是按回车时能够设置某个控件获得焦点,最好是用JavaScript实现该功能!
展开
2个回答
展开全部
这里是枣让按enter自动提交的,你修改凳悔局一下就可以用了
function isKeyTrigger(e,keyCode){
var argv = isKeyTrigger.arguments;
var argc = isKeyTrigger.arguments.length;
var bCtrl = false;
if(argc > 2){
bCtrl = argv[2];
}
var bAlt = false;
if(argc > 3){
bAlt = argv[3];
}
var nav4 = window.Event ? true : false;
if(typeof e == 'undefined') {
e = event;
}
if(bCtrl &&
!((typeof e.ctrlKey != 'undefined') ?
e.ctrlKey :
e.modifiers & Event.CONTROL_MASK >前源 0)) {
return false;
}
if( bAlt &&
!((typeof e.altKey != 'undefined') ?
e.altKey : e.modifiers & Event.ALT_MASK > 0)){
return false;
}
var whichCode = 0;
if (nav4) whichCode = e.which;
else if (e.type == "keypress" || e.type == "keydown") whichCode = e.keyCode;
else whichCode = e.button;
return (whichCode == keyCode);
}
function ctrlEnter(e){
var ie = navigator.appName == "Microsoft Internet Explorer" ? true : false;
if(ie){
if(event.keyCode == 13) {
submit();
}
else {
if(isKeyTrigger(e,13,true)){
submit();
}
}
}
}
function isKeyTrigger(e,keyCode){
var argv = isKeyTrigger.arguments;
var argc = isKeyTrigger.arguments.length;
var bCtrl = false;
if(argc > 2){
bCtrl = argv[2];
}
var bAlt = false;
if(argc > 3){
bAlt = argv[3];
}
var nav4 = window.Event ? true : false;
if(typeof e == 'undefined') {
e = event;
}
if(bCtrl &&
!((typeof e.ctrlKey != 'undefined') ?
e.ctrlKey :
e.modifiers & Event.CONTROL_MASK >前源 0)) {
return false;
}
if( bAlt &&
!((typeof e.altKey != 'undefined') ?
e.altKey : e.modifiers & Event.ALT_MASK > 0)){
return false;
}
var whichCode = 0;
if (nav4) whichCode = e.which;
else if (e.type == "keypress" || e.type == "keydown") whichCode = e.keyCode;
else whichCode = e.button;
return (whichCode == keyCode);
}
function ctrlEnter(e){
var ie = navigator.appName == "Microsoft Internet Explorer" ? true : false;
if(ie){
if(event.keyCode == 13) {
submit();
}
else {
if(isKeyTrigger(e,13,true)){
submit();
}
}
}
}
展开全部
<asp:textbox id="tbMb" runat="server"亏答槐 onkeydown="subMit(this,event)" >销友</asp:textbox>举源
function subMit(obj,el){
var e=el || window.event;
var curKey=e.which || e.keyCode;
if(curKey==13 && obj.value!="")
{
//操作自己东东
//防止页面被提交
if(window.event)event.returnValue=false;
else e.preventDefault();
}
}
function subMit(obj,el){
var e=el || window.event;
var curKey=e.which || e.keyCode;
if(curKey==13 && obj.value!="")
{
//操作自己东东
//防止页面被提交
if(window.event)event.returnValue=false;
else e.preventDefault();
}
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询