javascript-events

Adding Event Listener to dynamically created divs

让人想犯罪 __ 提交于 2019-12-24 00:59:36
问题 I am trying to add click event listener to my divs that I am creating in my JS dynamically. My Javascript snippet of function that is called each time to create the Div: var listDiv = document.createElement("div"); listDiv.className = "list"; listDiv.addEventListener = ('click',gotoOutcomesLO, false); The Function that is called by the click event: function gotoOutcomesLO(e){ if(typeof(Storage)!=="undefined"){ var ele = e.target; var text = ele.getAttribute("name"); sessionStorage.test = text

How to add search to some individual columns of DataTable in the footer?

ⅰ亾dé卋堺 提交于 2019-12-24 00:59:19
问题 I need to add filtering of different types (textbox, dropdown) to some(!) individual columns in DataTable to the footer. That is, I want to be able to search by a single column for each filter I add to the footer and the type of the filter will depend on a column, say, for the column 0 it's a textbox, for the column 1 it's a dropdown, for the column 5 it's a datepicker. Here's a test example. Note the new type of the constructor (DataTable, not dataTable). $("#my-table").DataTable({ //..... ,

Is event.preventDefault cancelling change events?

对着背影说爱祢 提交于 2019-12-24 00:54:32
问题 I have a certain situation I want to clarify for myself, and I would be glad if anyone has any experience with this issue and is willing to explain it to me. I have a textarea that has a change event handler: textarea.bind('change', function(event){ // do something }); Hypothetically, what if I have some sort of a click event handler that catches all user clicks: $(document).bind('click', function(event){ event.preventDefault(); }); Will this handler also cancel blur and change events for a

jQuery events work in Firefox, not Chrome

假装没事ソ 提交于 2019-12-24 00:47:29
问题 I registered some click events in my code. They function properly in Firefox (Windows and Mac) but don't execute in Chrome (tried Windows and Mac beta). The purpose of the JavaScript is to show the correct number of text inputs based on the value of the select element. Here is the code: http://www.savetherobots.org/users/jkost/substitutioncipher.php The script is bug-free according to Firebug. Is something wrong with the code? 回答1: Hai , For Select boxes, you need to register a handler for a

How stop file upload event using javascript

落爺英雄遲暮 提交于 2019-12-24 00:17:46
问题 I want to stop file upload event when i upload the file more than 5mb or if my file extension is not .jpg or .png . I found a code but when i try to upload the invalid file type then it only gives me alerts that i have upload the wrong file but it does not cancel the event. Here is the code <script> function checkFile(fieldObj) { var FileName = fieldObj.value; var FileExt = FileName.substr(FileName.lastIndexOf('.')+1); var FileSize = fieldObj.files[0].size; var FileSizeMB = (FileSize/5485760)

Mouseover/mouseenter not fired by browser on animated/moving element

我的未来我决定 提交于 2019-12-23 21:51:16
问题 If you have an element that has an animation to move it around, the mouseover and mouseenter events aren't fired unless the mouse is moved by the user. To demonstrate try the block of code below with jQuery. If you put your mouse in front of the moving div so you're not moving the mouse when the div passes by then the mouseover isn't fired and the block doesn't stop. In Firefox the mouseover event is fired without moving the mouse manually over the div, but only if you've moved the mouse at

Using jQuery's animate(), if the clicked on element is “<a href=”#“ …> </a>”, the function should still return false?

馋奶兔 提交于 2019-12-23 20:10:08
问题 I was reading jQuery's page for animate() http://api.jquery.com/animate/ Its examples don't mention about if using <a href="#" id="clickme">click me</a> ... $('#clickme').click(function() { $('#someDiv').animate({left: "+=60"}); }) we actually still have to return false like in the old days? $('#clickme').click(function() { $('#someDiv').animate({left: "+=60"}); return false; }) (but then, those examples didn't use a <a> for the "click me"... but used something else. Otherwise the page will

creating and removing <div> element in javascript

半腔热情 提交于 2019-12-23 19:57:13
问题 function labelOnClick () { function makeDivId(id) { return id + "_div"; }; var div = this.getElementById(makeDivId(this.id)); if (div) { div.parentNode.removeChild(div); } else { div = document.createElement("div"); div.innerHTML = "welcome"; div.id = makeDivId(this.id); this.appendChild(div); } } <label id="1" onclick="labelOnClick()" > BROWSER </label> <label id="2" onclick="labelOnClick()"> GAMING CONSOLE </label> In the above example, I'm trying to create a div element when a label is

Why is dragging in Raphaël broken by stopping propagation of mousemove in an enclosing element in the bubble phase?

亡梦爱人 提交于 2019-12-23 19:20:15
问题 I am trying to debug an event handling bug in a complicated web application, but I've reduced the problem to a simple example that demonstrates the behaviour that I'm confused by. My example page, based one of the Raphaël examples, is as follows: <!DOCTYPE html> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Raphaël · Drag-n-drop Example</title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script> <script

What's wrong with my event handler?

十年热恋 提交于 2019-12-23 18:27:41
问题 Let's say i was attaching an event handler of jquery click event to one of the function of my objects. But why it returns undefined on my properties ? var buttonView = { label : 'underscore', onClick : function(){ alert('clicked: ' + this.label); }, }; $('#bind').bind('click', buttonView.onClick); //clicked: undefined --> why is it undefined ? 回答1: You're passing the function referenced by buttonView.onClick , but it's association with buttonView is not retained . To retain the reference via