0

My onKeyPress ENTER key event works when deployed (in IE) on my localhost but does not work (in IE) when deployed on the test server. On the test server the ENTER event works in FireFox and also Chrome, just not in IE on the test server (but IE on the localhost it works)

        <script type="dojo/connect" event="onKeyPress" args="evt">
            // append a ENTER key press event handler to combobox to allow quick submit
             var key = evt.charOrCode;
             if (key == dojo.keys.ENTER) {
                if (!submitSearch(false)) {
                    dojo.stopEvent(evt);
                }
             }
        </script>

Can anyone offer insight as to why would this be?

4

1 回答 1

1

I think you're using the wrong event. Try using the "onKeyDown" event.

The keypress event should only be used when the pressed key also results in a character, such as the letters A-Z and so on (in a textbox for example).

I don't think the Enter-key (in this example) should trigger it, so that's why it might be worth trying to use the keydown event. Because that event will fire independently of the type of key that was pressed.

For some reasons IE considered the "Enter" key on your first machine as a visible character while on the second machine it didn't (could have to do with different versions), but anyways, I think the keydown event would be better.

You can read more about events (and browser support) here.

于 2013-04-12T06:23:35.197 回答