dom-events

Different behavior of blur event in different browsers

五迷三道 提交于 2019-11-27 14:56:20
问题 Consider this example where I have 2 input fields: <input id="a" /> <input id="b" style="display: none" /> And consider the following JavaScript, which is an attempt to do this: Show #b only when #a has focus and hide #b whenever #a loses focus, except when #a loses its focus to #b . $("#a").focus(function() { $("#b").show(); }); $("#a, #b").blur(function() { $("#b").hide(); }); $("#b").focus(function(){ $("#b").show(); }); $("#a").focus(function() { $("#b").show(); }); $("#a, #b").blur

The Order of Multiple Event Listeners

 ̄綄美尐妖づ 提交于 2019-11-27 14:10:22
问题 I've come across an oddity while using Prototype to handle click events. If you click the button in the code below, it will trigger three alerts: 'Click 1', 'Click 2' and 'Click 3'. Modern browsers will invoke the listeners in the order they are registered in, while IE8 (and perhaps older IE versions as well) will invoke them in the opposite order. I find this odd because I thought Prototype maintained and executed a queue of listeners, which should be browser independent. Is this not so? If

What is the height of a “line” in a wheel event? (deltaMode = DOM_DELTA_LINE)

别说谁变了你拦得住时间么 提交于 2019-11-27 13:27:37
问题 The wheel event in Firefox >= 17 has a deltaMode property. With the OS/mouse I'm using, it's set to 1 (or DOM_DELTA_LINE ). This setting means that the deltaX and deltaY event values are measured in lines and not pixels. Sure enough, if I pretend the deltas are pixels, scroll speeds are much slower than they normally are in Firefox. Chrome 31 by contrast uses a deltaMode of 0 (or DOM_DELTA_PIXEL ), which allows me to simulate scrolling with normal speeds. If I could convert the line values to

window.onpopstate, event.state == null?

牧云@^-^@ 提交于 2019-11-27 13:27:16
问题 I've read several question/answers on Stack Overflow and Googled the issue, I can't seem to get the event.state to come back with anything but null . I got that it wont work with the jQuery event, but when I do something like this: window.onpopstate = function (e) { console.log(e.state) } With something along the lines of a jQuery.ajax success calling history.pushState({ lastUrl: data.State }, data.Title, data.UrlKey); Neither Chrome (v19) or Firefox (v12) return anything but null? Am I

How to detect on-page 404 errors using JavaScript?

十年热恋 提交于 2019-11-27 11:36:49
问题 I have an HTML page where several JavaScript, CSS and images files are referenced. These references are dynamically injected and user can manually copy the HTML page and the support files to another machine. If some JS or CSS are missing, the browser complains in the console. For example: Error GET file:///E:/SSC_Temp/html_005/temp/Support/jquery.js I need somehow these errors reported back to me on the inline JavaScript of the HTML page so I can ask user to first verify that support files

Text in HTML Field to disappear when clicked?

时光总嘲笑我的痴心妄想 提交于 2019-11-27 11:31:54
问题 I can easily create a html input field that has text already in it. But when the user clicks on the input field the text doesn't disappears but stays there. The user then has to manually remove the text to type. How can I create an input field where when the user clicks on the input field box the text then disappear? 回答1: What you want to do is use the HTML5 attribute placeholder which lets you set a default value for your input box: <input type="text" name="inputBox" placeholder="enter your

Javascript / jQuery or something to change text every some seconds

不打扰是莪最后的温柔 提交于 2019-11-27 10:58:07
问题 Need JavaScript or jQuery something to change text every some seconds... with user doing anything. Example: "Welcome" changes to "Salmat datang" changes to "Namaste" etc after 3 secs and loops back. 回答1: As others have said, setInterval is your friend: var text = ["Welcome", "Hi", "Sup dude"]; var counter = 0; var elem = document.getElementById("changeText"); var inst = setInterval(change, 1000); function change() { elem.innerHTML = text[counter]; counter++; if (counter >= text.length) {

How to pass an event object to a function in Javascript?

对着背影说爱祢 提交于 2019-11-27 10:14:26
问题 <button type="button" value="click me" onclick="check_me();" /> function check_me() { //event.preventDefault(); var hello = document.myForm.username.value; var err = ''; if(hello == '' || hello == null) { err = 'User name required'; } if(err != '') { alert(err); $('username').focus(); return false; } else { return true; } } In Firefox, when I try to submit an empty value it throws up the error and sets the focus back to element. But same thing doesn't happen in IE as it throws up error and

Multiple JS event handlers on single element

為{幸葍}努か 提交于 2019-11-27 10:01:27
问题 I am working with an existing web app, in the app there are a variety of submit buttons on different forms, some using regular http post, some defining an onClick function, and some binding a js event handler to the button using a class on the element. What I want to do, is bind another event handler to these buttons by just adding a class to the buttons, but what I want to determine is will the new event handler be guaranteed to be executed, or could one of the form submit actions happen

Click source in JavaScript and jQuery, human or automated?

老子叫甜甜 提交于 2019-11-27 08:10:48
问题 We all know that you can simulate click or any other event on an element using one of these ways: $('#targetElement').trigger('eventName'); $('#targetElement').click(); I have encountered a situation in which, I should know how an element is clicked. I should know if it's been clicked automatically via code, or by pressing mouse button. Is there anyway I can do it without hacks or workarounds? I mean, is there anything built into browsers' event object, JavaScript, or jQuery that can tell us