如何禁用ENTER键时,asp.net textarea的是只读模式 [英] How to disable ENTER key when a asp.net textarea is in readonly mode

查看:258
本文介绍了如何禁用ENTER键时,asp.net textarea的是只读模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ASP.net:

 < textarea的ID =taskNotes=服务器级=taskNotes行=10的风格=>< / textarea的>

HTML生成ASP.net文本区:

 < textarea的名字=ctl00 $ ContentMain $ taskNotes级=taskNotesID =ContentMain_taskNotes的风格=行=10readOnly的=只读/&GT ;

如何禁用从当textarea的具有焦点和只读执行ENTER键。

我尝试以下,但无法完成:

  $('输入[CLASS = taskNotes]')。KEYDOWN(函数(五){
    如果(('.taskNotes')){//'。是()`VS中不填充为我完成...
        如果(e.key code === 13){
            亦即preventDefault();
            返回false;
        }
    }
});


解决方案

试试这个:

使用此为prevent回车键

  $(文件)。就绪(函数(){
    $(文件)。在('的keydown','.taskNotes [只读]​​',函数(E){
        如果(e.which === 13){
            亦即preventDefault();
            返回false;
        }
    });
});

或者作为替代,用这个来共元素的prevent重点:

  $(文件)。就绪(函数(){
    $(文件)。在('专注','.taskNotes [只读]​​',函数(E){
        $(本).blur();
    });
});

ASP.net:

<textarea id="taskNotes" runat="server" class="taskNotes" rows="10" style=""></textarea>

HTML generated ASP.net TextArea:

<textarea name="ctl00$ContentMain$taskNotes" class="taskNotes" id="ContentMain_taskNotes" style="" rows="10" readOnly="readonly"/>

How can I disable the ENTER key from executing when the textarea has the focus and readonly.

I tried the following but wasn't able to complete:

$('input[class=taskNotes]').keydown(function (e) {
    if (('.taskNotes')) { // '.is()` is not populating in VS for me to complete...
        if (e.keyCode === 13) {
            e.preventDefault();
            return false;
        }
    }
});

解决方案

Try this instead:

Use this to prevent enter key

$(document).ready(function () {
    $(document).on('keydown', '.taskNotes[readonly]', function(e){
        if (e.which === 13) {
            e.preventDefault();
            return false;
        }
    });
});

Or as an alternative, use this to prevent focus of the element altogether:

$(document).ready(function () {    
    $(document).on('focus', '.taskNotes[readonly]', function(e){
        $(this).blur();
    });
});

这篇关于如何禁用ENTER键时,asp.net textarea的是只读模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆