keydownda event.preventDefault () ishlamayapti

Bootstrap yorlig'i menyusidagi tugmachalarni bosib olishga urinib ko'rmoqchi bo'lsak-da, faqat ochko'zliklarni saqlash uchun ishlaydigan preventDefault() ga e'tibor bermaslik kerak.

document.onkeydown = function(e) {
  console.log("document catched the keydown event");

};

$('body > div > ul > li > a').on("keydown",function (e) {
  console.log("handled by the child - stop bubbling please");
  e.preventDefault();

});

Example: http://www.bootply.com/xUlN0dLRaV

bu erda nima yo'qolganman?

1
e.stopPropagation ()?
qo'shib qo'ydi muallif Jonas Grumann, manba
e.stopPropagation ()?
qo'shib qo'ydi muallif Jonas Grumann, manba
e.stopPropagation ()?
qo'shib qo'ydi muallif Jonas Grumann, manba
e.stopPropagation ()?
qo'shib qo'ydi muallif Jonas Grumann, manba
undan oldin javob berganidek, stopPrepagation dan foydalanishingiz kerak va bu, albatta, dublikat emas. turmush o'rtog'imiz nima uchun u ishlatgan vazifasi boshqa funktsiyadan farq qilmasligini so'ramayapti.
qo'shib qo'ydi muallif Motassem MK, manba
undan oldin javob berganidek, stopPrepagation dan foydalanishingiz kerak va bu, albatta, dublikat emas. turmush o'rtog'imiz nima uchun u ishlatgan vazifasi boshqa funktsiyadan farq qilmasligini so'ramayapti.
qo'shib qo'ydi muallif Motassem MK, manba
undan oldin javob berganidek, stopPrepagation dan foydalanishingiz kerak va bu, albatta, dublikat emas. turmush o'rtog'imiz nima uchun u ishlatgan vazifasi boshqa funktsiyadan farq qilmasligini so'ramayapti.
qo'shib qo'ydi muallif Motassem MK, manba

7 javoblar

Try e.stopPropagation()

e.stopPropagation() prevents the event from bubbling up the DOM tree, preventing any parent handlers from being notified of the event.

$('body > div > ul > li > a').on("keydown",function (e) {
  console.log("handled by the child - stop bubbling please");
  e.preventDefault();
  e.stopPropagation();
});

farq?

What's the difference between event.stopPropagation and event.preventDefault?

4
qo'shib qo'ydi
Agar siz savolni aniqlasangiz, uni takrorlash o'rniga ikki nusxani tanlang, biroq uni replikatsiya qilib, uni to'g'ri yopish uchun dublikat deb yozing. (Va, albatta, taxminan 1400 ta vakolatli nuqtada, siz to'g'ridan-to'g'ri ovoz berishingiz mumkin.)
qo'shib qo'ydi muallif T.J. Crowder, manba

Try e.stopPropagation()

e.stopPropagation() prevents the event from bubbling up the DOM tree, preventing any parent handlers from being notified of the event.

$('body > div > ul > li > a').on("keydown",function (e) {
  console.log("handled by the child - stop bubbling please");
  e.preventDefault();
  e.stopPropagation();
});

farq?

What's the difference between event.stopPropagation and event.preventDefault?

4
qo'shib qo'ydi
Agar siz savolni aniqlasangiz, uni takrorlash o'rniga ikki nusxani tanlang, biroq uni replikatsiya qilib, uni to'g'ri yopish uchun dublikat deb yozing. (Va, albatta, taxminan 1400 ta vakolatli nuqtada, siz to'g'ridan-to'g'ri ovoz berishingiz mumkin.)
qo'shib qo'ydi muallif T.J. Crowder, manba

Try e.stopPropagation()

e.stopPropagation() prevents the event from bubbling up the DOM tree, preventing any parent handlers from being notified of the event.

$('body > div > ul > li > a').on("keydown",function (e) {
  console.log("handled by the child - stop bubbling please");
  e.preventDefault();
  e.stopPropagation();
});

farq?

What's the difference between event.stopPropagation and event.preventDefault?

4
qo'shib qo'ydi
Agar siz savolni aniqlasangiz, uni takrorlash o'rniga ikki nusxani tanlang, biroq uni replikatsiya qilib, uni to'g'ri yopish uchun dublikat deb yozing. (Va, albatta, taxminan 1400 ta vakolatli nuqtada, siz to'g'ridan-to'g'ri ovoz berishingiz mumkin.)
qo'shib qo'ydi muallif T.J. Crowder, manba

e.preventDefault bilan bir qatorda, voqeani emirilishni oldini olish uchun e.stopPropagation() ni ham ishlatishingiz kerak. Sizning holatingizda ham soxta </​​code> -ni qaytarishingiz mumkin, bu ikkala narsani bajaruvchi:

$('body > div > ul > li > a').on("keydown",function (e) {
  console.log("handled by the child - stop bubbling please");
  return false;
});
0
qo'shib qo'ydi

e.preventDefault bilan bir qatorda, voqeani emirilishni oldini olish uchun e.stopPropagation() ni ham ishlatishingiz kerak. Sizning holatingizda ham soxta </​​code> -ni qaytarishingiz mumkin, bu ikkala narsani bajaruvchi:

$('body > div > ul > li > a').on("keydown",function (e) {
  console.log("handled by the child - stop bubbling please");
  return false;
});
0
qo'shib qo'ydi

e.preventDefault bilan bir qatorda, voqeani emirilishni oldini olish uchun e.stopPropagation() ni ham ishlatishingiz kerak. Sizning holatingizda ham soxta </​​code> -ni qaytarishingiz mumkin, bu ikkala narsani bajaruvchi:

$('body > div > ul > li > a').on("keydown",function (e) {
  console.log("handled by the child - stop bubbling please");
  return false;
});
0
qo'shib qo'ydi

e.preventDefault bilan bir qatorda, voqeani emirilishni oldini olish uchun e.stopPropagation() ni ham ishlatishingiz kerak. Sizning holatingizda ham soxta </​​code> -ni qaytarishingiz mumkin, bu ikkala narsani bajaruvchi:

$('body > div > ul > li > a').on("keydown",function (e) {
  console.log("handled by the child - stop bubbling please");
  return false;
});
0
qo'shib qo'ydi
Javascript UZB
Javascript UZB
99 ishtirokchilar

@js_uzb @vuejs_uz @react_uz @nodejs_uz @angular_uz @ngTashkent @yiiframework_uz @laravel_uz @linux_uzbek @python_uz @swift_uzb —————— @uzdevgroup @UzGeeksGroup ——— @UzDev_Jobs @jobs_uzb