javascript-events

Angular ng-submit called twice

你说的曾经没有我的故事 提交于 2019-12-23 07:38:08
问题 So, I have an angular form whose submit method is being hit twice, and I can't figure out why. I'm pretty new to Angular, so it's possible I'm overlooking something fairly simple... Html: <div ng-app="RegistrationApp" ng-controller="RegistrationController"> <form name="accountForm" ng-submit="submitAccount($event, accountForm, account)" novalidate> // inputs here... <button type="submit" class="btn btn-success pull-right" ng-disabled="accountForm.$invalid">Submit</button> </form> </div> Js:

How can jQuery's click() function be so much faster than addEventListener()?

蓝咒 提交于 2019-12-23 07:12:00
问题 I'm sure we've all seen the site for vanilla-js (the fastest framework for JavaScript) ;D and I was just curious, exactly how much faster plain JavaScript was than jQuery at adding an event handler for a click. So I headed on over to jsPerf to test it out and I was quite surprised by the results. jQuery outperformed plain JavaScript by over 2500% . My test code: //jQuery $('#test').click(function(){ console.log('hi'); }); //Plain JavaScript document.getElementById('test').addEventListener(

How to attach a keyup event to Custom Element shadowRoot

只愿长相守 提交于 2019-12-23 06:05:38
问题 I have searched for some time; but only find Polymer answers; or answers where EventListeners are put on DOM elements inside the shadowRoot. The effect I am trying to achieve with native Custom Elements: Only the focussed element should accept (and display) a keypress It is possible to attach a click event to the shadowRoot, it seems I am doing something wrong for the 'keyup' event. If I put the EventListener on the window all elements (of course) update with the same key info. window

Problem executing trackPageview with Google Analytics

孤街醉人 提交于 2019-12-23 06:01:28
问题 I'm trying to capture the clicks of certain download links and track them in Google Analytics. Here's my code var links = document.getElementsByTagName("a"); for (var i = 0; i < links.length; i++) { linkpath = links[i].pathname; if( linkpath.match(/\.(pdf|xls|ppt|doc|zip|txt)$/) || links[i].href.indexOf("mode=pdf") >=0 ){ //this matches our search addClickTracker(links[i]); } } function addClickTracker(obj){ if (obj.addEventListener) { obj.addEventListener('click', track , true); } else if

Problem executing trackPageview with Google Analytics

风流意气都作罢 提交于 2019-12-23 06:01:14
问题 I'm trying to capture the clicks of certain download links and track them in Google Analytics. Here's my code var links = document.getElementsByTagName("a"); for (var i = 0; i < links.length; i++) { linkpath = links[i].pathname; if( linkpath.match(/\.(pdf|xls|ppt|doc|zip|txt)$/) || links[i].href.indexOf("mode=pdf") >=0 ){ //this matches our search addClickTracker(links[i]); } } function addClickTracker(obj){ if (obj.addEventListener) { obj.addEventListener('click', track , true); } else if

Detect swipe gesture using javascript

拜拜、爱过 提交于 2019-12-23 05:29:16
问题 Hi I want to know how I can detect a swipe gesture using javascript. I dont want to use a separate library for this since I have the event object from my javascript callback at my disposal, which has everything I need such as deltaX, deltaY & absDeltaX & absDeltaY. My problem is what bounds do I need to set so that I can differentiate a swipe gesture from other gestures such as scrolling. This is a problem because sometimes when a user tries to swipe across the screen they also create a

Using beforeunload to execute task before page exit - Javascript/jQuery

两盒软妹~` 提交于 2019-12-23 05:24:04
问题 I'm trying to get an action executed before page leave, this requires a GET request being executed. I would like to give the GET request at least 50-100ms in order to get the request forwarded to the web server. I'm capturing the beforeunload action using: $(window).bind('beforeunload', function() { send_data(); }); Any tips? 回答1: You have the highest chance to get your request sent if you make it synchronous ( async: false in the $.ajax() options if you are using jQuery). But you cannot be

Javascript jump to anchor based on submit value/name

时光毁灭记忆、已成空白 提交于 2019-12-23 04:49:16
问题 I am working on a page that is basically a long form, with tables of info followed by a submit button after each table. The form submits to itself and changes the info in the tables based on user input. What I would like to do is have the page jump to "Section X" if "Submit Button X" is pressed, jump to "Section Y" if "Submit Button Y" is pressed, etc. I'm currently using this Javascript in the head of the doc to try and accomplish this: <script type="text/javascript"> var anchors = new Array

window.open(…) getting blocked in some browsers

我的梦境 提交于 2019-12-23 04:33:42
问题 I have a script where it opens a window for online application after executing some other scripts. window.open() is not called on any click. It is getting called in a script and browser prevents the new window from appearing. How to overcome this? here is the code.. window.open('/search/applyonline?jobid=".$jobDetails->getIdjob()."', 'applyurljob', 'height=550,\ width=800,\ toolbar=no,\ directories=no,\ status=no,\ menubar=no,\ scrollbars=yes,\ resizable=yes,\ left=200,\ top=250') 回答1: Popup

How can I load enough images to put a scroll bar on a users page to enable infinite scroll behaviour?

心已入冬 提交于 2019-12-23 04:26:54
问题 I am trying to implement an "infinite-scroll" behaviour to load some photos on a page and I'm using the following javascript to do so $(document).ready(function(){ $(window).scroll(function(){ var wintop = $(window).scrollTop(), docheight = $(document).height(), winheight = $(window).height(); var scrolltrigger = 0.10; if ((wintop/(docheight-winheight)) > scrolltrigger) { console.log('scroll bottom'); lastAddedLiveFunc(); } }); }); By default I would like to fill up the users page with just