javascript-events

How to trigger jQuery change event in code

走远了吗. 提交于 2019-12-17 03:03:47
问题 I have a change event that is working fine but I need to get it to recurse. So I have a function that is triggered on change that will "change" other drop downs based on a class selector (notice "drop downS", there could be more than one). This proxy change does not trigger the function and so fails. How can i get it to work? Code $(document).ready(function () { var activeDropBox = null; $("select.drop-box").change(function () { var questionId = $(this).attr("questionId"); var selectedAnswer

What exactly is the parameter e (event) and why pass it to JavaScript functions?

青春壹個敷衍的年華 提交于 2019-12-17 02:34:21
问题 Well, when I learned JavaScript, all the books and Internet articles I read showed code passing a parameter e to functions that handle JavaScript events, such as the code block below: function myEvent(e) { var evtType = e.type alert(evtType) // displays click, or whatever the event type was } I've always accepted that as being the way it is, but now I have some questions (this is very confusing to me): Where does this e come from? When I look at the entire JavaScript file, e does not seem to

Pass mouse events through absolutely-positioned element

蹲街弑〆低调 提交于 2019-12-17 02:27:49
问题 I'm attempting to capture mouse events on an element with another absolutely-positioned element on top of it. Right now, events on the absolutely-positioned element hit it and bubble up to its parent, but I want it to be "transparent" to these mouse events and forward them on to whatever is behind it. How should I implement this? 回答1: pointer-events: none; Is a CSS property that makes events "pass through" the element to which it is applied and makes the event occur on the element "below".

How can I get the destination URL for the onbeforeunload event?

倖福魔咒の 提交于 2019-12-16 22:24:15
问题 I've searched for hours, but I couldn't find a solution for this. window.onbeforeunload = warn; This doesn't work: function warn (e) { var destination = e.href; alert(destination ); } Okay, so to clear the things. If the user clicks on a link on the page itself, it is easy, because you can add an eventhandler to all of the links onclick event, but. I want to catch the address, what the user types into the url box of the browser. 回答1: Because it can't be done. The new location is private

How can I capture the right-click event in JavaScript? [duplicate]

陌路散爱 提交于 2019-12-16 22:12:07
问题 This question already has answers here : Is right click a Javascript event? (17 answers) Closed 6 years ago . I want to block the standard context menus, and handle the right-click event manually. How is this done? 回答1: Use the oncontextmenu event. Here's an example: <div oncontextmenu="javascript:alert('success!');return false;"> Lorem Ipsum </div> And using event listeners: el.addEventListener('contextmenu', function(ev) { ev.preventDefault(); alert('success!'); return false; }, false); Don

How can I capture the right-click event in JavaScript? [duplicate]

送分小仙女□ 提交于 2019-12-16 22:11:11
问题 This question already has answers here : Is right click a Javascript event? (17 answers) Closed 6 years ago . I want to block the standard context menus, and handle the right-click event manually. How is this done? 回答1: Use the oncontextmenu event. Here's an example: <div oncontextmenu="javascript:alert('success!');return false;"> Lorem Ipsum </div> And using event listeners: el.addEventListener('contextmenu', function(ev) { ev.preventDefault(); alert('success!'); return false; }, false); Don

Check if event exists on element [duplicate]

匆匆过客 提交于 2019-12-16 21:18:28
问题 This question already has answers here : jQuery find events handlers registered with an object (15 answers) Closed 3 years ago . Is there a way to check if an event exists in jQuery? I’m working on a plugin that uses custom namespaced events, and would like to be able to check if the event is binded to an element or not. 回答1: $('body').click(function(){ alert('test' )}) var foo = $.data( $('body').get(0), 'events' ).click // you can query $.data( object, 'events' ) and get an object back,

document.write clears page

时光毁灭记忆、已成空白 提交于 2019-12-16 20:37:04
问题 Why in the code below upon the call of document.write in the function validator() the form elements (the checkbox and button) are removed from screen? <!DOCTYPE html> <html> <head> <script type="text/javascript"> function validator() { if (document.myForm.thebox.checked) document.write("checkBox is checked"); else document.write("checkBox is NOT checked"); } </script> </head> <body> <form name="myForm"> <input type="checkbox" name ="thebox"/> <input type="button" onClick="validator()" name=

document.write clears page

点点圈 提交于 2019-12-16 20:36:34
问题 Why in the code below upon the call of document.write in the function validator() the form elements (the checkbox and button) are removed from screen? <!DOCTYPE html> <html> <head> <script type="text/javascript"> function validator() { if (document.myForm.thebox.checked) document.write("checkBox is checked"); else document.write("checkBox is NOT checked"); } </script> </head> <body> <form name="myForm"> <input type="checkbox" name ="thebox"/> <input type="button" onClick="validator()" name=

How to find out what character key is pressed?

别来无恙 提交于 2019-12-16 20:15:46
问题 I would like to find out what character key is pressed in a cross-browser compatible way in pure javascript. 回答1: "Clear" JavaScript: <script type="text/javascript"> function myKeyPress(e){ var keynum; if(window.event) { // IE keynum = e.keyCode; } else if(e.which){ // Netscape/Firefox/Opera keynum = e.which; } alert(String.fromCharCode(keynum)); } </script> <form> <input type="text" onkeypress="return myKeyPress(event)" /> </form> JQuery: $(document).keypress(function(event){ alert(String