开发者

Return enter key as false on disabled dropdownlists

I am using the below script to disable the default enter key behaviour on the controls Textbox开发者_开发技巧 and Dropdowns. However, if any of the textboxes or dropdown is made disabled the below script does not seem to work.

  txtTextBox1.Attributes.Add("onkeydown", "return (event.keyCode!=13);");

But if the textbox is made read-only. It works, but I do not have an option to make teh dropdown ReadOnly, I can only disable it.

Is there any work around?


Perhaps you can start higher up in the event chain. And allow everything except if one of these has focus.

function keykiller(event) {
        if (event.keyCode == 13 && !$(document.activeElement).is(input[type='text']) )       
        {
            event.cancelBubble = true;
            event.stopPropagation();            
            return false;
        }
    }

    window.addEventListener('keydown', keykiller, true);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜