javascript-events

How to count numbers of line in a textarea

点点圈 提交于 2019-12-12 10:07:05
问题 I want to make a dynamic textarea, it should increase in rows as the content increase. I am using this code: $("#text_textarea").keyup(function(e) { //splitting textarea value wrt '\n' to count the number of lines if ($(this).val().lastIndexOf('\n')!=-1) var x = $(this).val().split('\n'); $(this).attr( "rows" , x.length+1 ); }); But it fails when user continues to write without giving any new line \n (pressing Enter). 回答1: var keyUpTimeout = false; // Required variables for performance var

cloning an event object in javascript/jquery

▼魔方 西西 提交于 2019-12-12 09:49:17
问题 How can I create a completely separate and new event object that contains all of the same exact properties as a given event object e. So far I've tried the following but no luck: function myHandler(e) { // ... e = e.originalEvent; // method 1 var e2 = jQuery.extend(true, {}, e); // method 2 var e2 = JSON.parse(JSON.stringify(e)); // ... } EDIT: I will add more details to help clarify. Very similar to this question I am trying to do: div.dispatchEvent(e.originalEvent), but doing so results in:

jQuery keypress event wait 0.5 seconds for another user-keypress

社会主义新天地 提交于 2019-12-12 09:43:15
问题 I'm currently developing a live search for my website and I want to decrease some unnecessary request with some simple jQuery (of course I have a back-end-flood-control). I've got a keydown-event-listener for my search-field. This listener currenty only fires the ajax command for the php search-function if val().length is >= 3. But now I want an additional condition. So when the length is >= 3, I want to wait for about 0.5s or so if the user is performing another keypress. If he does, the

Javascript image onload

白昼怎懂夜的黑 提交于 2019-12-12 09:28:08
问题 I am trying to load a new image every time the previously loaded image has finished loading. The function create_photo_list works correctly. It creates an array of the photos that need to be loaded. If none need to be loaded then the array is empty. The problem is, when there are no more items to load the it keeps calling the load_next_photo function. The reason I call the registerEventHandler every time in the function is because if I don't, the function is not called when the next photo

CKEditor: HowTo destroy instance on blur?

和自甴很熟 提交于 2019-12-12 09:14:14
问题 i have a single html page with mulitple div elements on it. Each time a user clicks on on a div , it is replaced with an CKEditor on the fly: $('.editable').click(function() { editor = CKEDITOR.replace(this); }); Now, if the CKEditor instance loses its focus (blur event), i need to post the content to a separate script via ajax (if something changed) and destroy this instance: $('.editable').click(function() { editor = CKEDITOR.replace(this); editor.on('blur', function(e) { if (e.editor

Does Safari handle the paste event correctly?

徘徊边缘 提交于 2019-12-12 08:34:10
问题 I'm trying to write some code for Safari for handling the 'paste' event, but it doesn't seem to work right. According to the WebKit DOM reference, oncut , onpaste , and oncopy are all handled more-or-less like the W3C Clipboard API suggests. However, it doesn't work like I expect. I'm pasting image data, but as far as I've been able to tell, the problem I'm having applies to any kind of paste. This jsfiddle works just fine in Chrome, but not in Safari 6.0.4 on OSX. $(function () { console.log

Using Handlebars.js helpers to create active elements with jQuery?

假装没事ソ 提交于 2019-12-12 08:33:45
问题 Is it possible to within a Handlebars.js helper to create elements using jQuery and attach event handler to them? I'd like to be able to create active elements using helpers. Example: Handlebars.registerHelper("button", function(title) { var button = $('<button>').text(title); button.click(function() { alert("Button " + title + " clicked."); }); return $('<div>').append(button).html(); }); In the handlebars template I instantiate the button like this: {{{button "Click Me!"}}} I understand

Most efficient way to dynamically bind event handlers

只谈情不闲聊 提交于 2019-12-12 08:33:08
问题 Problem: I need to bind any number of event handlers to any number of elements (DOM nodes, window , document ) at dynamically runtime and I need to be able to update event binding for dynamically created (or destroyed) nodes during the lifetime of my page. There are three options that I can see for tackling this problem: I) Event delegation on window II) Direct event binding on each node III) Event delegation on common ancestors (which would be unknown until runtime and would potentially need

How to trace Javascript events (Stack Trace )?

穿精又带淫゛_ 提交于 2019-12-12 08:27:51
问题 In any programming language, I can trace any function and know which function is called by other. But in Javascript , I don't know how, since the code is not written by me and Firebug does not give this feature - as far as I know. An example : I want to display the function names of each function that is called when clicking on XYZ Element, and display them in order. Thanks. 回答1: Found this: A javascript stacktrace in any browser, James says they have a github account now function

Clicking a link when enter key is pressed using jQuery

本小妞迷上赌 提交于 2019-12-12 08:22:57
问题 I'm trying to make it so when a user is in a text box and they press enter, it is the same as clicking the link, in which case it should take them to another page. Here's what I have and it doesn't work. The code //jQuery $(document).ready(function() { //if focus is in the input box drivingSchoolInput $("#drivingSchoolInput").live("click", function() { //if enter key is pressed if(e.keyCode == 13) { //click the button and go to next page $("#button1").click(); } }); }); The markup <form> <div