javascript-events

View event listeners - Javascript

那年仲夏 提交于 2020-01-01 04:21:06
问题 I'm wondering if it is possible to view 1. How many event listeners 2. What type of event listener On a single web page. Reason being is becuase im using off(); method. I'm using this framework , which is basically jQuery but not. Yeah, I'm using off but the even't isn't removing and and I have a feeling there is more than one eventListener on the element. If it is not possible with javascript, it is possible in the browser? 回答1: Chrome has some built in tools. If you open up the element

How to set a rails variable equal to a javascript variable?

走远了吗. 提交于 2020-01-01 03:52:27
问题 I want to do something similar to How to pass a Javascript variable to Rails Controller? but I can't seem to get it working for my purposes. I'm using drag and drop jQuery to transfer "items" to "pods". Here's my code: function onReceive(id,pod_id){ var id = id; var pod_id = pod_id; confirm("Add " +id + " to " + pod_id + "?"); } What I want to do is really something like this: function onReceive(id,pod_id){ <% @pod_id = pod_id %> <% @id = id %> } But I know that the solution isn't quite that

Cross-browser JavaScript input live change/paste detection

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-01 03:10:13
问题 Is there a cross-browser way to detect live changes to an input field ? By live , I mean not when the field loses focus, and not on the next keypress, and so on. Immediately or something like it. Using combinations of jQuery and .change() , .keyup() , .bind('paste') and so on I can get working live change detection in some browsers, but not all . Using different combinations will make it work somewhat in other browsers. The trickiest thing to get working is mouse manipulation of the input

adding event as parameter within function, using addEventListener (Doesn't work in FF/IE). Javascript

最后都变了- 提交于 2020-01-01 03:01:15
问题 <html> <head> <title>FML</title> <script type="text/javascript"> function function1(e, div) { div.innerHTML="this works" document.getElementById('myspan').innerHTML= 'x-pos on click: ' + e.clientX div.addEventListener("mousemove", function(){test(event, this)}, true); } function test(e, div) { div.innerHTML+='<br/>so does this' //This doesn't work. Can't add event as a parameter to function that has to be executed when using addEventListener document.getElementById('myspan2').innerHTML= 'y

Is there a way to use event.preventDefault with focusOut? If not, why?

☆樱花仙子☆ 提交于 2020-01-01 01:40:12
问题 I would like to prevent the default event from a focusOut (or blur ) event and keep the focus set to the specific input field. This is what I have already tried: using event.preventDefault() at the beginning and at the end of the function (for test purposes, not for style) return false; to prevent propagation setting the focus back to the element directly in the element (but I found that the focus still switches because the focus switch is executed after the .on() function executes. I know I

Raphael canvas(background) onclick event

那年仲夏 提交于 2020-01-01 01:30:09
问题 I have been working with Raphael to create drag and drop shapes on a canvas. I do this using the .drag() function (supplied in the Raphael framework) along with my event functions. I have no issues doing this. I also have a function that creates a new shape onDblClick, the problem is, I can only attach the event to a shapes, or other elements I create. Adding events to a shape works like so: R = Raphael("canvas", "100%", "100%"), R.rect(100, 100, 25, 50).attr({fill: fillColor}).dblclick

JavaScript “is not a function” error when calling defined method

情到浓时终转凉″ 提交于 2020-01-01 01:25:09
问题 This is my code: request_xml: function() { http_request = false; http_request = new XMLHttpRequest(); if (http_request.overrideMimeType) { http_request.overrideMimeType('text/xml'); } if (!http_request) { return false; } http_request.onreadystatechange = this.response_xml; http_request.open('GET', realXmlUrl, true); http_request.send(null); xmlDoc = http_request.responseXML; }, response_xml:function () { if (http_request.readyState == 4) { if(http_request.status == 404 && countXmlUrl<=3) {

Execute my jQuery script after dynamically inserted jQuery library has finished loading

我与影子孤独终老i 提交于 2020-01-01 00:45:56
问题 I am dynamically inserting the jQuery library on a page via <script> tag: jq = document.createElement('script'); jq.setAttribute('src','//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js'); b.appendChild(jq); Then I have some jQuery script that needs to run after the jQuery library has finished loading and is ready for use: $(f).load(function() { $(f).fadein(1000); }); How can I make it wait for jQuery to load? 回答1: Specify an onload event at the to-be-inserted script tag: function

Javascript confirm dialog

眉间皱痕 提交于 2019-12-31 21:30:07
问题 I want to add a confirm dialog to a delete button to ask the user whether it is ok or not deleting the selected item. If not, nothing should happend, else a url should be executed. I know how to realize this via some javascript code but I am looking for a solution that has less code. I mean e.g. : <a href="mysite.de/xy/delete" onClick="...">Delete</a> Is it possible to put the whole functionality in the onClick element without having some extra javascript in the header? 回答1: Better (though

Jquery Listbox Change event does not fire on Keyboard scrolling

假如想象 提交于 2019-12-31 12:42:51
问题 I've got a simple Listbox on a HTML form and this very basic jQuery code //Toggle visibility of selected item $("#selCategory").change(function() { $(".prashQs").addClass("hide"); var cat = $("#selCategory :selected").attr("id"); cat = cat.substr(1); $("#d" + cat).removeClass("hide"); }); The change event fires fine when the current item is selected using the Mouse, but when i scroll through the items using the keyboard the event is not fired and my code never executes. Is there a reason for