0

キーボード イベントを HTML 要素の特別なクラス (mathquill スパン) に渡そうとしています。(キーの押下はより高いレベルでキャッチされるため、スプーンでフィードする必要があります。)これを行う標準的な方法は、この前の質問で提案されているように、jQuery の .trigger を使用するようです。ただし、そのソリューションは、私の側ではまったく何もしません。私は一生、何が悪いのかを見つけることができません。

このコードは、MathQuill ボックスを作成し、文字 'f' を入力することになっています。しかし、箱は空のままです。

<!DOCTYPE html>
<html>
    <head>
        <link rel="stylesheet" type="text/css" href="mathquill-master/mathquill.css">
    </head>

    <body>

        <!-- loading external scripts -->
        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
        <script type="text/javascript" src="mathquill-master/mathquill.min.js"></script>

        <!-- MathQuill box -->
        <span class="mathquill-editable" id="mathquill_box"></span>

        <script type="text/javascript">

            $(function() {
                $('.mathquill-editable').focus();

                // creating 'fake' custom event (pressing the 'F' key)
                // (this is taken directly from the answer to the previous question)
                var customKeyDownEvent = $.Event('keydown');
                customKeyDownEvent.bubbles = true;
                customKeyDownEvent.cancelable = true;
                customKeyDownEvent.charCode = 70; // key code for 'F'
                customKeyDownEvent.keyCode = 70;
                customKeyDownEvent.which = 70;

                // send the event to the MathQuill box
                $('.mathquill-editable textarea').trigger(customKeyDownEvent);

              });
            </script>

    </body>

</html>

どんな助けでも大歓迎です!

4

1 に答える 1