preventdefault

e.preventDefault() not bulletproof?

穿精又带淫゛_ 提交于 2020-01-02 07:20:09
问题 I have asked a similar question but didn’t get a real satisfying answer, so I will try again here. When I use code like this: $("#element") .on( 'click', function() { // do something } ) .on( 'touchstart', function(e) { e.preventDefault(); // do the same thing but on touch device like iPad f.e. // and more over PLEASE do not fire the click event also! } ); I am expecting that the click event is never never never fired (because of the hierarchy with which browser should work through the events

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

Is there an opposite function of preventDefault() in JavaScript?

ε祈祈猫儿з 提交于 2019-12-30 05:38:08
问题 I am counting words in a text field and after a certain amount of words, I use prevent default. In the else, I would like to re-enable the default commands. Does preventDefault( ) have an opposite function? Here is some sample code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>preventDefault</title> <style type="text/css"></style> <script type="text/javascript

Disable Hardware back button in cordova

北城以北 提交于 2019-12-25 16:36:13
问题 I know I'm not the first to ask this question, but none of the solutions for the previous questions work. I'm building a mobile application using Cordova, and I don't want the user to press the hardware back button because it might ruin the whole business scenario. What I need is to disable hardware back button completely from the application in order to allow the user to use only the in app buttons Thank you 回答1: Just fetch backbutton response and do prevent default. or do noting in that.

Correct way to set up a sequence of synchronous/asynchronous functions all of which can stop form submission and further processing?

巧了我就是萌 提交于 2019-12-25 08:58:14
问题 I need to call some functions in sequence on form submit button click - func1() -> func2() -> func3() ... -> func7() -> ... All these functions do some kind of validation/checking and if validation fails, display a confirmation dialog to the user. If the user confirms, the next function in queue is executed. Any of these functions could be doing some asynchronous task like sending Ajax request and depending on the result, showing the user some confirm dialog. Details I have asynchronous

Prevent default on link if parent hasClass()

一世执手 提交于 2019-12-25 08:09:07
问题 Simplified HTML: <ul> <li class="no-link"><a>Should not be clickable</a> <ul> <li><a>Should be clickable</a></li> <li><a>Should be clickable</a></li> </ul> </li> </ul> Javascript: jQuery(document).ready(function( $ ) { $('a').parent().click(function(e) { if($(this).hasClass('no-link')){ e.preventDefault(); } }); }) Works fine on the link that should not be clickable, but also affects the two descendant a tags. Why? I thought parent() only traversed up a single step in the DOM. I'm adding the

Prevent the default action. Working only in chrome

血红的双手。 提交于 2019-12-24 08:58:13
问题 Jquery: $(document).ready(function () { $('input[type=file]').uploadImage(); jQuery.event.props.push('dataTransfer'); $(".upload-cont").bind('dragenter', function (e) { $(".upload-cont").css("border", "1px dashed black;"); }); $(".upload-cont").bind('drop', function (e) { var files = e.dataTransfer.files; e.preventDefault(); }); $("body").bind('drop', function (e) { e.preventDefault(); }); }); In firefox 17,explorer 8 when dragging and dropping a file from desktop into browser the image will

PreventDefault on Blazor input

為{幸葍}努か 提交于 2019-12-23 12:19:33
问题 I have a simple application with an input field that should insert a predefined piece of text as you type. The code I have looks like this: <input type="text" bind="@PetitionInput" onkeydown="@PetitionHandleKeyDown" /> @functions { private int _petitionCharStep = 0; private string _petition = "This is a dummy text"; public string PetitionInput { get; set; } = string.Empty; void PetitionHandleKeyDown(UIKeyboardEventArgs arg) { PetitionInput += _petition[_petitionCharStep]; _petitionCharStep++;

jQuery trigger() and stopPropagation() on keydown event

寵の児 提交于 2019-12-23 09:46:48
问题 I am having a difficult time with keydown and stop propagation i do not want my page to refresh, i have tried every which way i can think of, my current code is <script> $(document).ready(function() { var e = jQuery.event( 'keydown', { which: $.ui.keyCode.ENTER } ); $('#id_number').trigger(e, function(event){ event.preventDefault(); event.stopPropagation(); }); }); </script> any idea on what i am doing wrong here? I thought that the event was called correctly, i have jquery and jquery ui

Vuejs - automatic event.preventDefault()

拟墨画扇 提交于 2019-12-23 07:59:35
问题 right now, I need to add event.preventDefault() to all of my click events in my Vue.js buttons: <button class="btn btn-primary" v-on:click="someAction($event)">Action</button></p> methods: { someAction (e) { e.preventDefault() console.log('in some action') }, } Does anyone know of a way have event.preventDefeault() be the default setting? Right now it's very annoying to have to include the event.preventDefault() in every click event. Thanks in advance! 回答1: You can use prevent modifier: