javascript-events

How can I automatically tab to the next field using jQuery?

本秂侑毒 提交于 2019-12-19 07:05:30
问题 In jQuery, how can I trigger the behavior of a user tabbing to the next input field? I've tried this: var e = jQuery.Event("keydown"); e.which = 9; // # Key code for the Tab key $("input").trigger(e); But triggering the event doesn't move the cursor to the next field. I suppose I could move the cursor manually using focus() , but deciding which field should be next is something the browser already knows how to do, so it seems much cleaner to just trigger a tab. Any ideas? 回答1: See the

How to distinguish scrolling by mouse from scrolling programmatically in JavaScript?

爱⌒轻易说出口 提交于 2019-12-19 05:53:43
问题 I am scrolling an overflowing DIV's content by changing the scrollLeft property in Javascript: setInterval(function(){ $('#scrollbox').scrollLeft($('#scrollbox').scrollLeft()+1); }, 50); However, I want to stop this as soon as the user scrolls the content themselves, using the mouse. I tried to detect this using the scroll event $('#scrollbox').scroll(function(){...}); however, my automatic scrolling above also triggers that event. How can I distinguish this and only react to user-initiated

jQuery unload event only for close window not for Link navigation

本秂侑毒 提交于 2019-12-19 04:55:21
问题 I am using this code for logging out user when closes the page, but the user will logout also when clicking on other links (same website): $( window ).unload(function() { $.ajax({url:"?logout&leave=yes", async:false}) }); Is there any way to distinguish between link navigation and real page close? EDIT: I am currently implemented this solution, but it lacks to detect page reload $('a').click(function(){ var url = $(this).attr("href"); window.onbeforeunload = null; $(window).unbind(

Hijacking onchange event without interfering with original function

心不动则不痛 提交于 2019-12-19 04:18:09
问题 im writing on a library i want to include on different pages who might already use the onchange event - is there any way to attach my event to onchange without removing the original one? EDIT: onchange on the window obj. not only a single element - onchange as in a hash change in the url etc. sorry if i confused them! 回答1: If I'm correct it sounds like you want to inject new code into an existing event. This may help you if you want a pure JavaScript solution and here is a fiddle

How to check if Chrome Dev Tools are opened? [duplicate]

走远了吗. 提交于 2019-12-19 04:05:55
问题 This question already has answers here : Find out whether Chrome console is open (14 answers) Closed 6 years ago . I found in the tutorial on codeschool.com (discover-devtools: http://discover-devtools.codeschool.com/chapters/1/challenges/3) that there is possibility to check if chrome developer tools are open? How to check it's state/get event of (cmd+alt+i) pressed? 回答1: google is your friend here function isInspectOpen() { console.profile(); console.profileEnd(); if (console.clear) console

Did windows update 2846071 break the handling of window.event.clientX clientY?

可紊 提交于 2019-12-19 04:04:57
问题 Did windows update http://support.microsoft.com/?kbid=2846071 break the handling of window.event.clientX and clientY ? It seems that Windows 7 machines using IE 9 or 10 now return something that looks like the window position (top left corner) rather than the mouse position within the window. The numbers look accurate, but may be negative. Or is that a "fix" and I should really be using something else for the mouse position. I was using it in window.onbeforeunload to detect a user leaving the

Button disable unless both input fields have value

徘徊边缘 提交于 2019-12-19 03:59:13
问题 I have a form with two input fields and a submit button on my page, I would like to have the feature that the 'submit' button is disabled until there are values on both two input fields. That's the button will be clickable if and only if there are values input in both fields. how to implement this with js and jQuery? Here is my page: <html> <body> <form method=post> <input type=text id='first_name'> <input type=text id='second_name'> <input type=submit value=Submit> </form> </body> </html> I

javascript addEventListener onStateChange not working in IE

柔情痞子 提交于 2019-12-19 03:22:59
问题 I have two colorbox popup boxes which show a youtube video in each. When they're finished playing, I'm trying to have them automatically close the colorbox window. This code below works perfect in firefox, but in IE I can't get addEventListener to work. I've tried attachEvent with no success. Can anybody offer any suggestions as to how to solve this? It seems simple but I'm exhausted trying to find a solution. By the way, this is my first time at stackoverflow and it's very impressive. UPDATE

Trigger click event on an AngularJS directive in Mocha test suite

假装没事ソ 提交于 2019-12-19 03:19:33
问题 I have a regular angular app with a directive. This directive contains an element with a ng-click="clickFunction()" call. All works well when I click that element. I now need to write a test for this click, making sure that this function was actually run when the element was clicked - this is what I'm having trouble with. Here's a jsfiddle to illustrate my issue: http://jsfiddle.net/miphe/v0ged3vb/ The controller contains a function clickFunction() which should be called on click. The unit

Determine whether a given JavaScript action has been initiated by user

孤街醉人 提交于 2019-12-19 02:49:23
问题 Is it possible to determine whether a given JavaScript action has been initiated by user? For instance I want to know whether a link was clicked by user or via jQuery fire event method? 回答1: event.which will be undefined if the event is triggered with code. jsFiddle. 来源: https://stackoverflow.com/questions/5948350/determine-whether-a-given-javascript-action-has-been-initiated-by-user