javascript-events

how to capture the key event from a view ?

断了今生、忘了曾经 提交于 2019-12-17 12:03:58
问题 I'm trying to capture the key event from a view as follows: myView = Backbone.View.extend({ el: $('#someDiv'), initialize: function(){ // initialize some subviews }, render: function(){ return this; }, events:{ 'keypress #someDiv': 'showKey' }, showKey: function(e){ console.log(e.keyCode); } }) That does not work ? ps: There a no [input] elements in the view or its subviews. I just need to know if the user presses any key and then do something on the view. 回答1: Key pressed goes to the focused

window.onload seems to trigger before the DOM is loaded (JavaScript)

自古美人都是妖i 提交于 2019-12-17 11:52:15
问题 I am having trouble with the window.onload and document.onload events. Everything I read tells me these will not trigger until the DOM is fully loaded with all its resources, it seems like this isn't happening for me: I tried the following simple page in Chrome 4.1.249.1036 (41514) and IE 8.0.7600.16385 with the same result: both displayed the message "It failed!", indicating that myParagraph is not loaded (and so the DOM seems incomplete). <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"

Do events handlers on a DOM node get deleted with the node?

无人久伴 提交于 2019-12-17 09:23:12
问题 (Note: I'm using jQuery below, but the question is really a general Javascript one.) Say I've got a div#formsection whose contents are repeatedly updated using AJAX, like this: var formSection = $('div#formsection'); var newContents = $.get(/* URL for next section */); formSection.html(newContents); Whenever I update this div, I trigger a custom event, which binds event handlers to some of the newly-added elements, like this: // When the first section of the form is loaded, this runs...

Do events handlers on a DOM node get deleted with the node?

£可爱£侵袭症+ 提交于 2019-12-17 09:23:05
问题 (Note: I'm using jQuery below, but the question is really a general Javascript one.) Say I've got a div#formsection whose contents are repeatedly updated using AJAX, like this: var formSection = $('div#formsection'); var newContents = $.get(/* URL for next section */); formSection.html(newContents); Whenever I update this div, I trigger a custom event, which binds event handlers to some of the newly-added elements, like this: // When the first section of the form is loaded, this runs...

What is the difference between Event.target, Event.toElement and Event.srcElement?

断了今生、忘了曾经 提交于 2019-12-17 08:55:11
问题 I have the following code: document.oncontextmenu = function(evt) { evt = evt || window.event; console.log(evt.target, evt.toElement, evt.srcElement); }; By clicking the right mouse button on a <div class="foo"></div> , returns this: div.foo, div.foo, div.foo By clicking the right mouse button on a <input> , returns this: input, input, input All seem to bring the same result. Is there any situation that one of them has different use than the others? 回答1: The event target is the element to

What is the difference between Event.target, Event.toElement and Event.srcElement?

旧街凉风 提交于 2019-12-17 08:55:02
问题 I have the following code: document.oncontextmenu = function(evt) { evt = evt || window.event; console.log(evt.target, evt.toElement, evt.srcElement); }; By clicking the right mouse button on a <div class="foo"></div> , returns this: div.foo, div.foo, div.foo By clicking the right mouse button on a <input> , returns this: input, input, input All seem to bring the same result. Is there any situation that one of them has different use than the others? 回答1: The event target is the element to

Find attached / bound events of an element using Chrome Development Tools / Firebug / IE Developer Toolbar

☆樱花仙子☆ 提交于 2019-12-17 08:31:47
问题 When inspecting a page's DOM, I would like to know the attached event(s) of an element quickly For example, if a button has this HTML DOM <button id="button1">Click Me</button> And somewhere (not in a place that I know in advance) it has an event attached, e.g. $("#button1").click(function(){...}); I know it can be done programatically ( Can I find events bound on an element with jQuery? ) but is there a way using just one of the developer tools for Chrome / Firefox / IE to see a list of

Wait for iframe to load in JavaScript

本小妞迷上赌 提交于 2019-12-17 07:31:20
问题 I am opening an iframe in JavaScript: righttop.location = "timesheet_notes.php"; and then want to pass information to it: righttop.document.notesform.ID_client.value = Client; Obviously though, that line isn't going to work until the page has fully loaded in the iframe, and that form element is there to be written to. So, what is the best/most efficient way to address this? Some sort of timeout loop? Ideally I would really like to keep it all contained within this particular script, rather

Wait for iframe to load in JavaScript

偶尔善良 提交于 2019-12-17 07:31:09
问题 I am opening an iframe in JavaScript: righttop.location = "timesheet_notes.php"; and then want to pass information to it: righttop.document.notesform.ID_client.value = Client; Obviously though, that line isn't going to work until the page has fully loaded in the iframe, and that form element is there to be written to. So, what is the best/most efficient way to address this? Some sort of timeout loop? Ideally I would really like to keep it all contained within this particular script, rather

Fullscreen API: Which events are fired?

好久不见. 提交于 2019-12-17 06:39:15
问题 I need to know which (DOM) events are fired when a user enter the fullscreen mode via the new Fullscreen API. I tried for example this snippet but it doesn't fire: jQuery('body').on('fullScreenChange', function() { alert("Fired!"); }); 回答1: Your link shows the answer... When full-screen mode is successfully engaged, the document which contains the full-screen element receives a fullscreenchange event. When full-screen mode is exited, the document again receives a fullscreenchange event. Note