小编Ste*_*e42的帖子

点击Enter键检查或选择复选框

新手 - 我想用这些复选框做两件事:

  1. 使用TAB键来选项卡,这部分有效
  2. 当我TAB通过选项时,我想ENTER按键选择该复选框,这部分不起作用

以下是示例代码.我正在使用复选框作为一个组.

有没有人有什么建议?

<!doctype html>
    <head>
        <title>test Radio buttons checkbox</title>
        <script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
        <script type="text/javascript">
            $(document).ready(function(){
                $('input:checkbox[name=Colors]').keypress(function(event) {
                    var keycode = (event.keyCode ? event.keyCode : event.which);
                    if (keycode == 13) {
                        Checkbox_to_RadioButton(this);
                        alert("Enter key was pressed");
                    }   
                    event.stopPropagation();
                });

                $('input:checkbox[name=Colors]').click(function(){
                    Checkbox_to_RadioButton(this);
                });
            });

            function Checkbox_to_RadioButton(box){
                $('input:checkbox[name=' + box.name + ']').each(function(){
                    if (this != box)
                        $(this).attr('checked', false);
                });
            }
        </script>
    </head>

    <body>
        <h1>test Radio buttons checkbox</h1>
        <form name="form1">
            <input type="text" id="dname" …
Run Code Online (Sandbox Code Playgroud)

forms checkbox jquery enter

10
推荐指数
3
解决办法
2万
查看次数

标签 统计

checkbox ×1

enter ×1

forms ×1

jquery ×1