javascript-events

How to prevent AutoPostBack when DropDownlist is selected using jQuery

流过昼夜 提交于 2020-01-11 11:03:35
问题 I want to show a confirm dialog when the user selects an item in a DropDownList. If the user presses "Cancel", I want to stop the postback. Here is the function I add to the onchange event: function imitateConfirmUnload(event) { if (window.onbeforeunload = null) return true; return confirm("Are you sure you want to navigate away from this page?\n\nYou have unsaved changes\n\nPress OK to continue or Cancel to stay on the current page."); } And this is the relevant bit of code in my startup

Iterate getEventListeners() return object

≯℡__Kan透↙ 提交于 2020-01-11 04:04:24
问题 I am searching for a way to iterate the object getEventListeners(obj) returns. This way, I wouldn't need specific code to iterate event listener types, or to check if they exist on the checked element. My goal is to remove some event listeners from an element. For example remove all mouse related ones, and keep the others. Thanks 回答1: getEventListeners() will return simple JS object, you can iterate objects like this: var listeners = window.getEventListeners(document.body); Object.keys

jquery event.target is_a_child_of(element)

匆匆过客 提交于 2020-01-11 00:09:09
问题 Given element , a variable containing a javascript object/DOM element, how do I determine if the event.target is an element inside element or not? function(event){ // assume that var element exists in this scope if(event.target == a_child_of(element)) // do something } <div id="myDiv"> <div class="innerDiv"> <input type="text"/> </div> </div> If element is myDiv , an event occurring on the inner div or the input, or any other element that may exist inside myDiv should cause the statement to

What is the difference of using addEventListener?

此生再无相见时 提交于 2020-01-10 14:38:10
问题 What is the main difference between of using this... document.addEventListener('mousedown', function() { // code }, false); ...and this? document.onmousedown = function() { // code } Will there be any different result or any cause? 回答1: onclick is a property, like the onclick attribute can be placed in HTML. It has best browser support, however, it is primitive, as reassigning it overwrites the first (like any object property). addEventListener() , as the name suggests, allows you to register

how to implement Search function using Javascript or jquery

怎甘沉沦 提交于 2020-01-10 10:49:17
问题 here i write code where all persons names comes from Facebook API . and it is showing on lightbox. now i want to implement search functionality using javasciprt/jquery . Can you help me how should i implement search function ? <div> <input type="text" id="search-criteria"/> <input type="button" id="search" value="search" onClick="tes();"/> </div> <fieldset> <legend>Invite Facebook Friend</legend> <div class="fbbox"> <img src="images/User.png" class="fbimg" /> <div class="fix"><label for=

how to remove print header/footer with code

懵懂的女人 提交于 2020-01-10 05:15:47
问题 I am using the following code to print a page within my application... <html><body onload=""window.print();"">" sHtmlBody = sHtmlBody & "<body>" The window.print() is working fine. I know once the print comes up I can manually go into the settings and remove headers and footer. On IE I know that I have to go to print preview and then remove the print headers. However, is there some line of code which does this automatically so the users of the application don't have to do this? EDIT:

Issue with onClick() and middle button on mouse

一曲冷凌霜 提交于 2020-01-10 05:07:07
问题 <a href="<?=$rowz[0]?>" onClick="countLinks('<?=$row[6]?>','<?=$indexl?>')">[Link <?=$j++?>]</a> The problem is that it doesn't work with middle button on IE or firefox. In fact, the countLinks using middle button is called only with chrome. I think I need a Jquery function like mouseup event, just I don't know how call that function, which it calls countLinks with those parameters parameters. Any help? 回答1: You're right. You need a mousedown or mouseup event to determine which mouse button

Can't remove event listener

怎甘沉沦 提交于 2020-01-10 04:37:06
问题 Can anyone tell why bt2 event listener is not getting removed in if block. As when I remove the event listener in the p function, it's getting removed without any error or bug. I am pretty sure there might be any stack or scope problem due to which event listener is not getting removed but I can't figure out what that could be. And I know that event listener is not getting removed as with the succeeding clicks on bt2 element all the preceding event listeners are also running again, as the

Create a pause inside a while loop in javascript

扶醉桌前 提交于 2020-01-09 07:12:30
问题 I would like to create a pause inside a while loop so that I can create n animations that each appear 3 seconds after the other. I've tried the following, but it doesn't work. Would love to have someone show me what I'm doing wrong. Thanks!! i=0; while (i < n) { someanimation(); setTimeout(function(){ i++; }, 3000); }; 回答1: setTimeout does not pause; it asks Javascript to run some other code later. Googling for "setTimeout loop" tells you exactly what you need to know. If you look around a

When does a click become a hold?

强颜欢笑 提交于 2020-01-07 09:52:30
问题 I'm making a web app where a button's behavior is different if the user clicks vs holds the button. I have been experimenting with different timings and it got me wondering if there is any established standard for this kind of thing. For clarification: I am wondering if there is an exact timing that is standard. Below is the code I am using with 150ms being the threshold for a hold. function onMouseDown() { var holdTimeout = setTimeout(function() { //Hold code (also cancels click event) },