javascript-events

dispatchEvent not preforming event, but returns true

不问归期 提交于 2019-12-22 17:40:28
问题 On MDC's site they have a cool demo of dispatchEvent that works fine in my chrome 15. I'm trying to take an event object and pass it into dispatchEvent, and have set up a simple case here where you record events as an array then will replay them. In essence, I set up a window listener for click, and then preform window.dispatchEvent(recordedEvent) . I'm unable to determine why my event object from the event listener will not preform the same way as the event from initMouseEvent in the MDC

Javascript on tick or on untick events for a checkbox?

自作多情 提交于 2019-12-22 16:33:16
问题 Is it possible to fire an event when a checkbox is ticked, and a different one when it's unticked? At the moment I'm using $("#booking_checkboxes").on("change", "input", function(){}); but I'd like to know if the checkbox just changed to be ticked, or just changed to be unticked. What's the easiest way to do this? 回答1: Nope, the same event is fired in both cases. You'd have to check for the value of the input in the event callback: $("#booking_checkboxes").on("change", "input", function(){ if

Javascript on tick or on untick events for a checkbox?

风流意气都作罢 提交于 2019-12-22 16:32:33
问题 Is it possible to fire an event when a checkbox is ticked, and a different one when it's unticked? At the moment I'm using $("#booking_checkboxes").on("change", "input", function(){}); but I'd like to know if the checkbox just changed to be ticked, or just changed to be unticked. What's the easiest way to do this? 回答1: Nope, the same event is fired in both cases. You'd have to check for the value of the input in the event callback: $("#booking_checkboxes").on("change", "input", function(){ if

Iterating through same form elements

强颜欢笑 提交于 2019-12-22 12:41:30
问题 If a form has same tag repeatedly. How to get its value in javascript. <script> function validate() { //get all values of elmone } </script> <form> <input type="text" size="15" value="Hello World" name="elmOne"> <input type="text" size="15" value="next Hello World" name="elmOne"> <input type="button" onclick="javascript:validate()" value="validate"> </form> Thanks.. 回答1: it is not a common practice to name two different text input element with a common name. However, back to the question, you

Global keyDown/keyPress events in EmberJS without having to set focus

给你一囗甜甜゛ 提交于 2019-12-22 11:06:40
问题 I used to have a jQuery app, that had a 'keydown' event once the document was ready. Basically, anytime a user hit a key, it would match the keycode and do something. Now I ported this app to Ember and life became difficult for 2 reasons: 1) The only time a 'keyDown' event can be registered is when the containing element/View has a focus on it. The only way this can be done with non-input fields is by setting the tabindex value, to achieve this, I do this: didInsertElement:function(){ this.$(

Unable to handle onbeforeunload event using Angular Service

余生长醉 提交于 2019-12-22 10:07:44
问题 I have the following callback for my onbeforeUnload event in one of my service. In my app.run block I have: window.onbeforeunload = Services.beforeWindowClose; and this method is in a service: this.beforeWindowClose = function (event) { var currentState = $state.current.name; if (currentState !== constant.LOGOUT) { $rootScope.$broadcast("close"); if (Utilities.isSavePending) event.returnValue = constant.MSG; } } In my controllers I have : $scope.$on("close", function () { Utilities

How to capture event when allowClear option of select2 is chosen?

故事扮演 提交于 2019-12-22 08:55:35
问题 I've tried to capture select2:clearing event $("#my-select").on("select2:clearing", function (e) { console.log('cleared'); }); (jsfiddle) but it is not fired. I've also tried other versions (like select2:removed etc., see another question with similar problem), but it also doesn't work. I use select2 4.0.0-beta2. 回答1: The changelog of select2 4.0.0-beta2 states: Removed events select2-clearing - Use select2:unselecting instead https://github.com/select2/select2/releases 回答2: This works: $("

addEventListener for new elements

岁酱吖の 提交于 2019-12-22 08:32:21
问题 Consider a basic addEventListener as window.onload=function(){ document.getElementById("alert") .addEventListener('click', function(){ alert("OK"); }, false); } where <div id="alert">ALERT</div> does not exist in the original document and we call it from an external source by AJAX. How we can force addEventListener to work for newly added elements to the documents (after initial scan of DOM elements by window.onload )? In jQuery, we do this by live() or delegate() ; but how we can do this

Javascript event css background image loaded

喜夏-厌秋 提交于 2019-12-22 08:16:12
问题 Is there any way to detect that a css background image has been loaded? By using normal tags this would be easy but I need to use a css background because I'm placing divs over the image. The reason why I need to detect that this image has been loaded is that I don't want to start preload additional images before the background image is shown. 回答1: You can force the background image to download to the client's browser using traditional javascript methods to pre-load images. Once its

Javascript event css background image loaded

两盒软妹~` 提交于 2019-12-22 08:15:07
问题 Is there any way to detect that a css background image has been loaded? By using normal tags this would be easy but I need to use a css background because I'm placing divs over the image. The reason why I need to detect that this image has been loaded is that I don't want to start preload additional images before the background image is shown. 回答1: You can force the background image to download to the client's browser using traditional javascript methods to pre-load images. Once its