javascript-events

jquery: on vs live

不想你离开。 提交于 2019-12-17 16:53:52
问题 I am curious why when I replace .live() with .on() my events don't work after inserting AJAX's response via html() method. Assume I have html structure: <div class="a"> <a href="" class="alert-link">alert</a> <a href="" class="ajax-update">update</a> </div> and jquery code something like: $('.alert-link').on("click", function(){ alert('abc'); return false; }); and ajax-update will trigger request, which response will be alert update and I will insert it into parent() . Then pressing again

keycode on keydown event

。_饼干妹妹 提交于 2019-12-17 16:48:13
问题 I'm using keydown event Where I get the keycode and convert it to charcode. But I got a problem where in keyboard is press 2 it gives 50 and charcode as 2 When I press 2 in numpad it gives keycode 98 , so when I convert charcode a 回答1: That is happening because you are using the keyCode member, for example, a lower case 'a' and an upper case 'A' have the same keyCode, because is the same key, but a different charCode because the resulting character is different. To get the charCode, you

How to get mouse pointer position using javascript for internet explorer?

假装没事ソ 提交于 2019-12-17 16:39:31
问题 I am developing a web page where I have set an image in a <div> dynamically. It works in Firefox but it fails in IE. The question is: how to get mouse pointer position in IE? I am using the following code for getting mouse pointer position function getCursorXY(e) { CurX = (window.Event) ? e.pageX : event.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft); CurY = (window.Event) ? e.pageY : event.clientY + (document.documentElement

Is My Page Being Loaded from the Browser Cache?

落花浮王杯 提交于 2019-12-17 16:27:36
问题 I have a "new items" badge on a page that I want to update immediately the page is loaded from the cache (i.e. when hitting "Back" or "Forward" to return to this page). What is the best way to accomplish this? The setup is pretty simple. The layout for the app looks for new items every 8 seconds, and updates the badge + list of items accordingly. $(function() { setInterval( App.pollForNewItems, 8000 ); }); When someone navigates away from this page to look at the details of an item, a lot can

How to bind to all custom events in jQuery

心不动则不痛 提交于 2019-12-17 16:23:15
问题 I know it's not possible to bind to all DOM events and I know you can bind to multiple events by supplying a space-separated list. But is it possible to bind to all custom events (preferably filtered by a wildcard pattern like 'abc*' or name-space)? Edit: To clarify, I have created some custom widgets that respond to some custom events. For example, they all handle an event called 'stepReset' and resets their internal models. After I've written these, I realized events don't bubble down, so

properly bind javascript events

混江龙づ霸主 提交于 2019-12-17 15:56:09
问题 I am looking for the most proper and efficient way to bind javascript events ; particularly the onload event (I would like the event to occur after both the page AND all elements such as images are loaded). I know there are simple ways to do this in jQuery but I would like the more efficient raw javascript method. 回答1: There are two different ways to do it. Only one will work; which one depends on the browser. Here's a utility method that uses both: function bindEvent(element, type, handler)

jQuery event bubbling

时光怂恿深爱的人放手 提交于 2019-12-17 15:46:09
问题 I want to understand how exactly to interpret bubbling. Does it mean going up the HTML code hierarchy or something else? Secondly, I was going through an example and I could not understand the last part where it says The P-based click handler listens for the click event and then prevents it from being propagated (bubbling up) What does this mean? 回答1: return false; will prevent "bubbling". It's used to stop default actions like checking a checkbox, opening a select, a click, etc. To stop

Handle refresh page event with javascript

谁说胖子不能爱 提交于 2019-12-17 15:44:18
问题 Is it possible to use javascript to handle the event of refreshing page? What i want is get notice if user do one of these behaviours: refresh page by pressing F5 close tab or browser enter a new url then press enter on browser to display a warning message? Thanks in advance! 回答1: You don't want the refresh, you want the onbeforeunload event. http://msdn.microsoft.com/en-us/library/ms536907(VS.85).aspx Sample code from article <HTML> <head> <script> function closeIt() { return "Any string

Escaping double quotes in JavaScript onClick event handler

流过昼夜 提交于 2019-12-17 15:37:38
问题 The simple code block below can be served up in a static HTML page but results in a JavaScript error. How should you escape the embedded double quote in the onClick handler (i.e. \"xyz)? Note that the HTML is generated dynamically by pulling data from a database, the data of which is snippets of other HTML code that could have either single or double quotes. It seems that adding a single backslash ahead of the double quote character doesn't do the trick. <script type="text/javascript">

Regular expression for all printable characters in JavaScript

China☆狼群 提交于 2019-12-17 12:48:22
问题 Looking for a regular expression for that validates all printable characters. The regex needs to be used in JavaScript only. I have gone through this post but it mostly talks about .net, Java and C but not JavaScript. You have to allow only these printable characters : a-z, A-Z, 0-9, and the thirty-two symbols: !"#$%&'()*+,-./:;<=>?@[] ^_`{|}~ and space Need a JavaScript regex to validate the input characters is one of the above and discard the rest. 回答1: If you want to match all printable