event-handling

How does jQuery's new on() method compare to the live() method in performance?

我的未来我决定 提交于 2019-11-27 07:14:26
问题 jQuery has a new method called on() that is recommended to replace delegate() , live() , and .bind() . For example, using both methods: $('#some-button').on('click', function() { //do something when #some-button is clicked }); $('#some-button').live('click', function() { //do something when #some-button is clicked }); Which one performs better? (I do know that both of these event contexts are at the document level.) 回答1: As I understand .live() and .on() , the two examples you have included

How to unbind a specific event handler

眉间皱痕 提交于 2019-11-27 07:11:38
Code: $('#Inputfield').keyup(function(e) { if(e.which == 13) { functionXyz(); } else { functionZyx(); } }); $(document).keyup(function(exit) { if (exit.keyCode == 27) { functionZzy(); } }); Question: How to remove the keyup event handler of keyCode == 27 and keep the other $(document).keyup event handlers intact? You have to use a named function so you can reference that specific handler when calling .unbind() , like this: function keyUpFunc(e) { if (e.keyCode == 27) { functionZzy(); } } $(document).keyup(keyUpFunc); Then later when unbinding: $(document).unbind("keyup", keyUpFunc); Your are

Javascript click event handler - how do I get the reference to the clicked item?

你说的曾经没有我的故事 提交于 2019-11-27 07:07:14
My HTML: <div id="x" onclick="clickHandler(event)"> <div id="button1">This turns green</div> <div id="button2">This turns blue</div> </div> So first of all, why am I supposed to be passing "event" into the click handler and is event some kind of system keyword? Also, since the click handler is identified on the container div, how do I know which button has been clicked? event is an Event object which is created automatically when an event is fired. Note that you don't have to call it event (I tend to call it simply e ). That Event object has a number of properties which describe the event it

How to handle multiple click events with same Sub

廉价感情. 提交于 2019-11-27 07:04:25
问题 I'm making a game for my visual basic course. I have multiple picture boxes that when clicked will reveal a hidden image individually. The point of the game is to find the matching pictures (simple enough). On the easiest level, I have 16 picture boxes. The number of picture boxes increases as the difficulty increases. For each picture box, I currently have an event handler as follows (default created by visual studio): Private Sub pictureBox1_Click(ByVal sender As System.Object, ByVal e As

Java - mouseMoved() event handling in Swing

落爺英雄遲暮 提交于 2019-11-27 07:00:00
问题 I want to listen for mouse movements and clicks in my JFrame. To do this, I've added a MouseListener implemented like this: (whole code of View class is at https://gist.github.com/2837224, Board class is at https://gist.github.com/2837231) class BattleshipsFrame extends JFrame { private final Board playerBoard, opponentBoard; private View view; /** Main window constructor. */ BattleshipsFrame() { ... ... ... //creating and displaying boards playerBoard = new Board(); opponentBoard = new Board

“after” looping indefinitely: never entering mainloop

青春壹個敷衍的年華 提交于 2019-11-27 06:52:39
问题 This is my first post. I started coding when considering a career swap two months ago and am working on a Tetris clone. I've implemented most of the core features, but cannot get the game to refresh continually with an after loop. I'm using Tkinter to produce my Gui and am trying out event oriented programming. My understanding is that after(Time, Event) from Tkinter should schedule whatever the Event callback function is to occur after a delay specified by Time . I think that the code is

jQuery change method on input type=“file”

我的未来我决定 提交于 2019-11-27 06:51:46
I'm trying to embrace jQuery 100% with it's simple and elegant API but I've run into an inconsistency between the API and straight-up HTML that I can't quite figure out. I have an AJAX file uploader script (which functions correctly) that I want to run each time the file input value changes. Here's my working code: <input type="file" size="45" name="imageFile" id="imageFile" onchange="uploadFile()"> When I convert the onchange event to a jQuery implementation: $('#imageFile').change(function(){ uploadFile(); }); the result isn't the same. With the onchange attribute the uploadFile() function

Using the GWT Scheduler

谁都会走 提交于 2019-11-27 06:49:37
I'm having a tough time understanding the difference between various methods of the com.google.gwt.core.client.Scheduler interface, specifically, the scheduleDeferred , scheduleFinally , and scheduleIncremental methods. I'm hampered in my understanding, I think, by my unfamiliarity with the browser event processing loop, to which the Scheduler documentation refers. Would you please explain how these methods differ from each other, and how they work in relation to the browser event loop? JavaScript (in a browser) is single threaded. The event loop model means, we're always in exactly one of two

Fire event on enter key press for a textbox

匆匆过客 提交于 2019-11-27 06:48:57
I have the following asp.net textbox control. <asp:TextBox ID="txtAdd" runat="server" /> After the user writes something in this textbox and presses the ENTER key, I want to run some code from codebehind. What should I do? Using jQuery I captured ENTER key and fired some hidden button event $(document).ready(function(){ $(window).keydown(function(e){ if(e.keyCode == 13) $('#<% addbtn.ClientID %>'.click(); }); }); Is there any better way ? ASPX: <asp:TextBox ID="TextBox1" clientidmode="Static" runat="server" onkeypress="return EnterEvent(event)"></asp:TextBox> <asp:Button ID="Button1" runat=

Implementing jQuery's “live” binder with native Javascript

℡╲_俬逩灬. 提交于 2019-11-27 06:45:24
I am trying to figure out how to bind an event to dynamically created elements. I need the event to persist on the element even after it is destroyed and regenerated. Obviously with jQuery's live function its easy, but what would they look like implemented with native Javascript? Andrew Whitaker Here's a simple example: function live(eventType, elementId, cb) { document.addEventListener(eventType, function (event) { if (event.target.id === elementId) { cb.call(event.target, event); } }); } live("click", "test", function (event) { alert(this.id); }); The basic idea is that you want to attach an