preventdefault

Checkboxes are being checked before click handler is even called

倖福魔咒の 提交于 2019-12-19 10:25:35
问题 I have the following snippets: http://jsfiddle.net/L7rne/5/ and http://jsfiddle.net/L7rne/6/ It turns out that if you pause execution of the script in the click event handler, then the checkbox is checked, even though there is event.preventDefault() . I tried this in Firefox 7 and Chrome 15 and both behave in the same way. I'm almost sure that it's a correct behaviour but somehow I cannot find any reference why it's like that. Could someone point me in the right direction? EDIT: When you

How exactly does event.preventDefault() affect the DOM?

淺唱寂寞╮ 提交于 2019-12-19 07:32:37
问题 Based on someone's advice I added this line $('body').on('touchstart', function(event){ event.preventDefault() }) in my mobile webapp to disable the native app bouncing in iOS. It works great for disabling the bounce but gives me some weird behavior elsewhere in DOM. Click events that don't work, etc. I was hoping to get a better understanding of what this does and how to work around it's effects elsewhere in the DOM. Thanks! EDIT: I have these two lines: $('body').on('touchstart', function(e

event.preventDefault() function not working in IE

冷暖自知 提交于 2019-12-16 19:31:47
问题 Following is my JavaScript (mootools) code: $('orderNowForm').addEvent('submit', function (event) { event.preventDefault(); allFilled = false; $$(".required").each(function (inp) { if (inp.getValue() != '') { allFilled = true; } }); if (!allFilled) { $$(".errormsg").setStyle('display', ''); return; } else { $$('.defaultText').each(function (input) { if (input.getValue() == input.getAttribute('title')) { input.setAttribute('value', ''); } }); } this.send({ onSuccess: function () { $('page_1

form should not submit on enter if focus is not on submit button

二次信任 提交于 2019-12-14 03:15:41
问题 I have a requirement where user cannot submit the form if he press enter key unless focus will be on submit button. Using following code, I am able to do that, but now the issue is, if I have any enter key event attached specific to any field (e.g. if I want to attach enter key event to one textfield for some special requirement), it is not allowing me due to the script I have written below.. <script> $(document).keydown(function(event) { if (event.keyCode == 13) { var $focusedItem = $

Perform AJAX request before continuing with default action [closed]

做~自己de王妃 提交于 2019-12-13 11:30:03
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 6 years ago . I have a basic AJAX request like so: $.ajax({ url: 'check_password.php', type: 'post', data: 'password='+password, dataType: 'json', success: function(json) { if (json['success']) { //Continue with default action

e.preventDefault is not a function - Jest React

此生再无相见时 提交于 2019-12-13 04:33:45
问题 Trying to test the following onChange event: JEST / ENZYME for React JS it(" Render method : test 1st onChange event :", () => { baseProps.onChange.mockClear(); wrapper.setState({ localState:{} }); wrapper.find('#individual-series').simulate('change',{target:{value:""}}) wrapper.update() wrapper.find('#individual-series').simulate('change', event) expect(wrapper.state().localState).toEqual('test'); expect(baseProps.addNewSeries).toHaveBeenCalled(); }); I saw this as an answer on StackOverflow

Both event.preventDefault() and event.returnValue = false don't work in Firefox

旧街凉风 提交于 2019-12-12 17:27:50
问题 I have tried these to snippets of codes, the first one works in IE and Chrome, the second one works in Chrome only, but both of them don't work in Firefox. What I want is to stop the page from going to other pages via links $('.album a').click(function(){ event.returnValue = false; //other codes }) $('.album a').click(function(){ event.preventDefault(); //other codes }) Edit: This snippet from Ian worked for me $('.album a').click(function(e){ e.preventDefault(); //other codes }); 回答1: You

Preventing ctrl+z in browser

Deadly 提交于 2019-12-12 13:18:23
问题 I used the code sample below to disable ctrl + c and ctrl + v and it works. I used similar mechanics to disable ctrl + z (undo) in the browser but it doesn't work. var ctrlDown = false; var ctrlKey = 17, vKey = 86, cKey = 67, zKey = 90; $('body').keydown(function(e) { if (e.keyCode == 17 || e.keyCode == 91) { ctrlDown = true; }; }).keyup(function(e) { if (e.keyCode == 17 || e.keyCode == 91) { ctrlDown = false; }; }); $("body").keydown(function(e){ if ((ctrlDown && e.keyCode == zKey) ||

Using preventDefault on a submit button

帅比萌擦擦* 提交于 2019-12-12 10:57:29
问题 I am trying to solve a problem offered by a jQuery textbook. It reads like this "The data is submitted even though no entries have been made, to fix this you must stop the default action of the submit button. To do that, code the preventDefault method of the event object in the if statement at the end of the file, as in figure 10-6 note* here's what the code looks like in 10-6 that's not working for me when I tag it on to the end of my code as the book suggests. if (isValid == false) { event

Can't submit after preventDefault

本小妞迷上赌 提交于 2019-12-12 05:05:38
问题 I use a script for form validation (validationEngine) and a script for file upload (uploadify). To best manage my form submission: validationEngine detects if my form can be sent. If I can submit, I upload my files Once all my uploaded files ( onQueueComplete uploadify), I submit my form. If I make an alert('foo'); in my onQueueComplete, it works. But if I submit my selector.submit() ... nothing happens. $(function() { $('#file_upload').uploadify({ 'fileSizeLimit' : '2048KB', 'auto': false,